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:05:05 -0700
- Thread-topic: NSImage from bitmap - then delete bitmap
>
>> On 27 Jul 2016, at 09:33, Trygve Inda <email@hidden> wrote:
>>
>>
>>
>> If the worker thread calls window.imageRep = myResult; it is possible that
>> the main thread is in the middle of a call like:
>>
>> [[window.imageRep]
>> drawInRect:fromRect:operation:fraction:respectFlipped:hints:]
>>
>> So when the setter (called from the worker thread) replaces the old imageRep
>> with a new one, the old one's retain count goes to zero and it will
>> disappear.
>>
>> I know atomic makes the call safe as far as a vaild value is concerned, but
>> the main thread could call window.imageRep and get a valid value (because it
>> is atomic), but before it is able to use this value, the worker thread calls
>> the setter which causes the imageRep obtained by the main thread to be
>> released.
>
> No it couldn’t - because when the main thread calls window.imageRep it gets a
> reference which, whether it assigns it to a variable or just uses it in in a
> chained call (like you have above with drawInRect:.) is retained by the main
> thread during the life of that variable or during the call. So it doesn’t
> matter if the worker thread replaces it after the call to window.imageRep, the
> main thread’s reference remains valid and usable and is only released when
> it’s finished with it and only then gets deallocated (if nothing else is
> referencing it)
>
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.
_______________________________________________
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