• 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: Newbie question: how to release an object that has been autoreleased
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Newbie question: how to release an object that has been autoreleased


  • Subject: Re: Newbie question: how to release an object that has been autoreleased
  • From: "M. Uli Kusterer" <email@hidden>
  • Date: Wed, 22 Sep 2004 18:43:28 +0200

At 8:04 Uhr -0700 22.09.2004, James Bucanek wrote:
In this particular case, these buffers are being created (from the Pool object) and handed out to several threads which fill them with data.

Aaaahh! Danger, Will Robinson!

Autorelease pools are per-thread. If you autorelease an object and hand it off to another thread, the original thread may dispose of it while the new one is still working on it. So, in this case your second thread *must* retain it.

I know that you could theoretically have the first thread in a loop which doesn't exit until the second thread has finished, but to rely on that is very fragile.

So, just do as the designers of Cocoa's memory management scheme intended and retain your object in the second thread. Then the first one can release it whenever it wants and nobody has to wait for the other.
--
Cheers,
M. Uli Kusterer
------------------------------------------------------------
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden
  • Follow-Ups:
    • Re: Newbie question: how to release an object that has been autoreleased
      • From: James Bucanek <email@hidden>
References: 
 >Re: Newbie question: how to release an object that has been autoreleased (From: James Bucanek <email@hidden>)

  • Prev by Date: Re: Newbie question: autorelease sends autorelease
  • Next by Date: Hacking the Finder with APE to turn the proxy icon into a drop target..
  • Previous by thread: Re: Newbie question: how to release an object that has been autoreleased
  • Next by thread: Re: Newbie question: how to release an object that has been autoreleased
  • Index(es):
    • Date
    • Thread