On Jan 26, 2012, at 3: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?
> Excuse me if I'm being dumb.

The block is an object.  It has retained myController.  myController has 
retained the block because it's been assigned to the completionHandler property.

By the way, a retain cycle doesn't need two objects.  An object can retain 
itself and that's a cycle.

Cheers,
Ken


_______________________________________________

Cocoa-dev mailing list ([email protected])

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to