Re: ARC and blocks
Re: ARC and blocks
- Subject: Re: ARC and blocks
- From: Conrad Shultz <email@hidden>
- Date: Thu, 26 Jan 2012 16:25:49 -0800
On 1/26/12 4:21 PM, Kyle Sluder wrote:
> 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).
D'oh. Thanks for the pointer (no pun intended). I guess I still have
some reading to do about ARC... I thought that keeping the various
__bridge attributes straight was hard enough, now I have to go read up
on interaction with blocks too.
--
Conrad Shultz
Synthetiq Solutions
www.synthetiqsolutions.com
_______________________________________________
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