Re: NSImage from bitmap - then delete bitmap
Re: NSImage from bitmap - then delete bitmap
- Subject: Re: NSImage from bitmap - then delete bitmap
- From: Trygve Inda <email@hidden>
- Date: Tue, 26 Jul 2016 19:47:47 -0700
- Thread-topic: NSImage from bitmap - then delete bitmap
>
>> On 27 Jul 2016, at 12:05 PM, Trygve Inda <email@hidden> wrote:
>>
>> How is it retained by the main thread without an explicit retain call?
>>
>> I would be no different than a main thread calling:
>>
>> someVar [[MyObj alloc] init]
>> [someVar doSomething];
>>
>> If a worker thread were able to call [someVar release] between these two
>> lines, the doSomething call could fail.
>
>
> The atomic setter method probably looks something like this:
>
> - (void) setImageRep:(NSImageRep*) rep
> {
> @synchronized( self )
> {
> [rep retain];
> [_imageRep autorelease];
> _imageRep = rep;
> }
> }
>
> i.e. the old value is autoreleased. Which thread’s pool gets that autorelease
> is a matter for consideration though. I have no idea if it’s just left to the
> caller’s pool, or if there are steps taken to ensure it ends up in the main
> pool. Even if it’s the caller’s pool, unless you’re draining it on each loop,
> it may only ever get drained when the thread ends, which is safe. But it could
> accumulate a lot of unreleased memory which is another potential problem.
>
> Threads are tricky ;)
And BTW I am draining the pool on each loop of the worker thread.
_______________________________________________
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