• 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: Blocks and Methods...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Blocks and Methods...


  • Subject: Re: Blocks and Methods...
  • From: Mikkel Islay <email@hidden>
  • Date: Sat, 28 Jan 2012 21:56:03 +0100

On 28 Jan 2012, at 20:50, R wrote:

> That is precisely what is giving me the confusion.  If retained the
> received block in a NSMutableArray, the block should stick around (via
> a strong array pointer) for another method.  It only stays around if I
> equate the block to a typedef variable and then put that variable in
> the array.  I'm using ARC.

Blocks are allocated on the stack, unlike other objective-C objects. As a consequence, they cannot be retained and are destroyed with the stack. That means they must be copied to the heap explicitly to be available beyond the scope they were created in, as Ken Thomases wrote.
With ARC, blocks are normally copied to the heap automatically as required. However, adding an object to a container implicitly casts it to id, which is not automatically copied with ARC. Hence, you must copy it explicitly.

Mikkel
_______________________________________________

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: 
 >Blocks and Methods... (From: R <email@hidden>)
 >Re: Blocks and Methods... (From: Mike Abdullah <email@hidden>)
 >Re: Blocks and Methods... (From: R <email@hidden>)
 >Re: Blocks and Methods... (From: Ken Thomases <email@hidden>)
 >Re: Blocks and Methods... (From: R <email@hidden>)

  • Prev by Date: Re: Recently Opened in Doc
  • Next by Date: Re: Blocks and Methods...
  • Previous by thread: Re: Blocks and Methods...
  • Next by thread: Re: Blocks and Methods...
  • Index(es):
    • Date
    • Thread