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: Ondra Cada <email@hidden>
- Date: Wed, 22 Sep 2004 20:28:11 +0200
John,
On 22.9.2004, at 19:48, John Mikros wrote:
If these buffer objects are being passed between threads then I'd
imagine that you'd want to avoid autorelease like the plague.
Nope. Why, on earth?
You don't want the object autoreleased while you're still using it in
the other thread.
Why? That does not make real sense. Autorelease is just a delayed
release.
If the object is used in another thread, it is bound to be retained
there (and eventually /auto/released there). Thus, no harm in in being
autoreleased in the first thread, for it won't be deallocated (until it
is /auto/released in all the threads in which it is used).
There's of course another, *quite different* danger: in the accessor
implementation itself, the object may be retained twice or released
twice or some similar havoc may arise due to the sad fact both the
threads may perform the same code at the same time. That's what locks
are for; you can see in the list archives how to use them for writing
thread-safe accessors:
http://www.cocoabuilder.com/archive/message/2002/8/6/62229
Note that (in the getter, where it is much more safe) autorelease is
still used.
---
Ondra Čada
OCSoftware: email@hidden http://www.ocs.cz
private email@hidden http://www.ocs.cz/oc
_______________________________________________
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