Le 19 avr. 2010 à 11:35, Henk Kampman a écrit :

> Have a look at the following code
> 
> -(void) test
> {
>       testString = NULL;
>       
>       dispatch_async(dispatch_get_global_queue(0, 0), ^{
>               dispatch_async(dispatch_get_main_queue(), ^{
>                       
>                       NSString* aString = [[NSMutableString alloc] init];
>                       NSLog(@"retainCount: %d",[aString retainCount]);
>                       
>                       testString = [aString retain];
>                       
>                       [aString release];
>                       
>                       dispatch_async(dispatch_get_main_queue(), ^{
>                               NSLog(@"retainCount: %d",[testString 
> retainCount]);
>                       });
>               });
>       });
> }
> 
> As expected the output is:
> 
> retainCount: 1
> retainCount: 1
> 
> However when I change [aString release] to [aString autorelease] the output 
> shows:
> 
> retainCount: 1
> retainCount: 2
> 
> Why?
> 
> BTW I first noticed this behavior when my application started leaking the 
> QTMovie objects I was creating in a block.
> 
> -

Because you should never expect something from retainCount.
See archives for details.

-- Jean-Daniel




_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to