Re: Storing a block in a CF/NSMutableDictionary?
Re: Storing a block in a CF/NSMutableDictionary?
- Subject: Re: Storing a block in a CF/NSMutableDictionary?
- From: Kyle Sluder <email@hidden>
- Date: Fri, 08 Apr 2011 21:03:14 -0700
On Fri, Apr 8, 2011 at 5:56 PM, Rick Mann <email@hidden> wrote:
> Hmm. Reading the docs there again, it also says:
>
> "Typically, you shouldn’t need to copy (or retain) a block. You only need to make a copy when you expect the block to be used after destruction of the scope within which it was declared. Copying moves a block to the heap."
>
> So, I expressly copied my block and stored the copy in the dictionary. That worked (I mistakenly conflated the fact that keys typically get copied, not objects).
But it references a stack variable, which is going to get destroyed as
soon as the syntactical block enclosing the declaration of your code
block (*sigh* for namespace collision) goes out of scope.
If you reference a stack variable from your block, you cannot allow
that block to escape the scope of that variable.
--Kyle Sluder
_______________________________________________
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