• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: ARC and blocks
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ARC and blocks


  • Subject: Re: ARC and blocks
  • From: Fritz Anderson <email@hidden>
  • Date: Thu, 26 Jan 2012 16:48:52 -0600

On 26 Jan 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…];

There is a MyViewController object named myController

> myController.completionHandler =  ^(NSInteger result)

It retains a void(^)(NSInteger) block (or a copy thereof.

> {
>    [myController dismissViewControllerAnimated:YES completion:nil];

The block refers to myController, so the block automatically retains it. myController <-> block is a cycle

>    myController = nil;

Now the block no longer refers to myController, so myController is released.

> };

When myController is deallocated, it releases the block. No cycle.

>
> 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?


	— F


_______________________________________________

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


References: 
 >ARC and blocks (From: "Jan E. Schotsman" <email@hidden>)

  • Prev by Date: Re: ARC and blocks
  • Next by Date: Re: ARC and blocks
  • Previous by thread: Re: ARC and blocks
  • Next by thread: Re: ARC and blocks
  • Index(es):
    • Date
    • Thread