Re: ARC and blocks
Re: ARC and blocks
- Subject: Re: ARC and blocks
- From: Jean-Daniel Dupas <email@hidden>
- Date: Thu, 26 Jan 2012 23:41:13 +0100
Le 26 janv. 2012 à 22:51, Jan E. Schotsman a écrit :
> Hello,
>
> This code is given in the "Transitioning to ARC Release Notes" as an example of accomodating blocks in an ARC environment:
>
> __block MyViewController *myController = [[MyViewController alloc] init…];
> // ...
> myController.completionHandler = ^(NSInteger result) {
> [myController dismissViewControllerAnimated:YES completion:nil];
> myController = nil;
> };
>
> Supposedly this avoids a retain cycle. But where is the cycle? At least two objects are needed for a cycle. What is the second one?
The first object if myController.
The second object is the block.
myController retains the block.
the block retains myController.
You have your retain cycle.
-- Jean-Daniel
_______________________________________________
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