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: Rick Mann <email@hidden>
- Date: Fri, 08 Apr 2011 17:56:51 -0700
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).
Thanks.
--
Rick
On Apr 8, 2011, at 17:51 , Kyle Sluder wrote:
> On Fri, Apr 8, 2011 at 5:25 PM, Rick Mann <email@hidden> wrote:
>> Hi. In my garbage collection-required app, I'm trying to store a code block (void (^)(void)) in a CFMutableDictionary. The docs says copy/retain/release can be sent to a block, suggesting this can be done. But it's not working. When I later retrieve the block and call it, I get an EXEC_BAD_ACCESS.
>>
>> This is when the block references an NSObject declared & allocated in the block's enclosing scope. If I don't access that variable, it executes fine.
>
> As explained in the Blocks Programming Guide, you should not allow
> blocks that reference stack storage to escape that scope. See
> "Patterns to Avoid":
> http://developer.apple.com/library/ios/#documentation/cocoa/Conceptual/Blocks/Articles/bxUsing.html
>
> --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