Re: "Capturing 'self' strongly in this block is likely to lead to a retain cycle"
Re: "Capturing 'self' strongly in this block is likely to lead to a retain cycle"
- Subject: Re: "Capturing 'self' strongly in this block is likely to lead to a retain cycle"
- From: Sean McBride <email@hidden>
- Date: Mon, 09 Jul 2012 17:51:39 -0400
- Organization: Rogue Research Inc.
On Mon, 9 Jul 2012 11:03:50 -0500, Fritz Anderson said:
>You correctly describe the cycle. In practice, NSOperationQueue probably
>releases the block when it's done with it, and breaks the cycle, but
>clang can't know that, so it has to warn of the "likely" cycle.
>
>You can break this by having a strong reference to self that the block
>can manage independently.
>
> __block MyClass * blockSelf = self;
> [self.operationQueue addOperationWithBlock:^{
> [blockSelf bar];
> blockSelf = nil;
> }];
A contortion I guess those of us switching from GC to ARC will have to sprinkle around. :( Shame.
--
____________________________________________________________
Sean McBride, B. Eng email@hidden
Rogue Research www.rogue-research.com
Mac Software Developer Montréal, Québec, Canada
_______________________________________________
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