Re: ARC and blocks
Re: ARC and blocks
- Subject: Re: ARC and blocks
- From: Greg Parker <email@hidden>
- Date: Thu, 26 Jan 2012 15:16:19 -0800
On Jan 26, 2012, at 1:51 PM, Jan E. Schotsman wrote:
> 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?
Remember that blocks are objects too. If you are not careful then the view controller points to the block object and the block object points back to the view controller.
--
Greg Parker email@hidden Runtime Wrangler
_______________________________________________
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