Re: ARC and blocks
Re: ARC and blocks
- Subject: Re: ARC and blocks
- From: Kyle Sluder <email@hidden>
- Date: Thu, 26 Jan 2012 16:21:47 -0800
On Thu, Jan 26, 2012 at 2:44 PM, Conrad Shultz
<email@hidden> wrote:
> However, __block variables are NOT retained automatically by a block
> during capture, so this breaks the retain cycle.
__block variables *are* retained under ARC:
http://clang.llvm.org/docs/AutomaticReferenceCounting.html#misc.blocks
The important bit of the code that Jan cited isn't that myController
is annotated with __block, it's that the block nils out the
myController variable when it executes.
This works because the block is a completion handler—it's only
executed once, so there's a sensible time for it to engage in cleanup.
Long-lived block arguments, however, need a different strategy. This
is why the Transitioning to ARC Release Notes also recommend
strategies that use __weak (or __unsafe_unretained if you're targeting
older OSes).
--Kyle Sluder
_______________________________________________
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