Re: @synchronized crashing with ARC
Re: @synchronized crashing with ARC
- Subject: Re: @synchronized crashing with ARC
- From: James Montgomerie <email@hidden>
- Date: Thu, 31 May 2012 17:42:50 +0100
It looks a bit suspicious to me that you're instantiating the dictionary in your hidden "… work ..." code, then using it in the visible code, but not releasing it.
Is it possible that the dictionary started out as an ObjC object that you don't own, and you used a (__bridge CFDictionaryRef) cast to assign it to myDictionary, expecting it to stick around until the autorelease pool pops?
That's not what is guaranteed to happen under ARC - the system is now free to release the dictionary when the last strong pointer referring to it goes out of scope. A CF reference is not an ARC-managed pointer, so it doesn't count as a strong pointer.
If this is the case, there are a few solutions. Making myDictionary an 'NSDictionary *' is the easiest one, since that will be fully managed by ARC, so it will keep a reference to it until you test it and the function exits.
Jamie.
On Thursday, 31 May 2012 at 16:47, Antonio Nunes wrote:
> I have a function that looks essentially like this:
>
> static void *kMyVLFContext = &kMyVLFContext;
> Boolean myFunction(CFURLRef path)
> {
> CFDictionaryRef myDictionary = NULL;
>
> @synchronized(kMyVLFContext) {
> … work …
> }
>
> return myDictionary != NULL;
> }
>
> This function works fine with manual memory management. After compiling with ARC though, a crash occurs on line "@synchronized(kMyVLFContext) {". I wouldn't think this should be affected by ARC at all. Any hints as to what might be afoot here, or is it more likely something else, earlier on is causing a failure here (e.g. stomping kMyVLFContext)?
>
> Removing the lock causes the function to return successfully, but may of course cause issues on occasions when the function is called from several threads at once.
>
> -António
>
> ----------------------------------------------------
> It isn't so important to do great things,
> as to do what you do with great love.
> ----------------------------------------------------
>
>
>
>
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden (mailto: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 (http://lists.apple.com)
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden (mailto:email@hidden)
_______________________________________________
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