• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSImage from bitmap - then delete bitmap
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: NSImage from bitmap - then delete bitmap
      • From: Roland King <email@hidden>
    • Re: NSImage from bitmap - then delete bitmap
      • From: Graham Cox <email@hidden>
References: 
 >Re: NSImage from bitmap - then delete bitmap (From: Roland King <email@hidden>)

  • Prev by Date: Re: NSImage from bitmap - then delete bitmap
  • Next by Date: Re: NSImage from bitmap - then delete bitmap
  • Previous by thread: Re: NSImage from bitmap - then delete bitmap
  • Next by thread: Re: NSImage from bitmap - then delete bitmap
  • Index(es):
    • Date
    • Thread