Re: Newbie question: how to release an object that has been autoreleased
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