Re: NSImage from bitmap - then delete bitmap
Re: NSImage from bitmap - then delete bitmap
- Subject: Re: NSImage from bitmap - then delete bitmap
- From: Roland King <email@hidden>
- Date: Wed, 27 Jul 2016 10:52:57 +0800
>
> I would think that even with a retain it could get weird...
>
> The main thread wants to use the imageRef property so it calls:
>
> myRef = [window.imageRef];
> [myref retain];
>
> If right between these calls, the worker thread calls setImageRef (on a
> property with atomic, copy), then the retain call in the main thread might
> be on something that has already gone away.
>
> I just don't see how I can safely set the property on a worker thread and
> read it on the main thread without some risk of it being released behind my
> back.
As Graham points out, and as we used to discuss often back in the old MRR days, atomic getters likely put the value in the autorelease pool, you should go see if that’s the case or not, if so, it’s protected for as long as that pool isn’t drained, and it’s your pool on the main thread, so it won’t be drained between those calls. In that case you don’t even need to add the extra retains, however for good practice, why not.
If atomic getters don’t work like that then they are fairly useless.
_______________________________________________
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