Re: Unexpected behaviour with autorelease pool
Re: Unexpected behaviour with autorelease pool
- Subject: Re: Unexpected behaviour with autorelease pool
- From: Jean-Daniel Dupas <email@hidden>
- Date: Sun, 14 Dec 2008 22:49:46 +0100
Le 14 déc. 08 à 22:36, Filip van der Meeren a écrit :
I think I have found the answer to your question; when executing the
following code, I get a few strange results...
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSNumber *n0 = [NSNumber numberWithInt:1];
NSLog(@"n0: %d", [n0 retainCount]);
[n0 release];
NSLog(@"n0: %d", [n0 retainCount]);
[n0 release];
NSNumber *n1 = [NSNumber alloc];
NSLog(@"n1: %d", [n1 retainCount]);
n1 = [n1 initWithInt:1];
NSLog(@"n1: %d", [n1 retainCount]);
[n1 release];
[pool release];
The code above results in the following log:
2008-12-14 22:32:54.997 SmallTest[556:10b] n0: 2 <===============
Thats strange....
2008-12-14 22:32:55.003 SmallTest[556:10b] n0: 1
2008-12-14 22:32:55.004 SmallTest[556:10b] n1: -1 <===============
That is normal
2008-12-14 22:32:55.005 SmallTest[556:10b] n1: 2 <===============
Whooooow, overretained an object ;-)
My guess is that NSNumber is over-retaining itself within its
initializer. Nothing for you to worry about.
This is a typical worry-case for that nice Apple programmer... You
should file a bug-report...
DO NOT MAKE ANY assumption over retainCount. NSNumber is not over
retaining, it is caching small number for efficiency. This is not a bug
Respect the Memory management rules and all will be fine.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden