Re: Question about scope of "convenience objects"
Re: Question about scope of "convenience objects"
- Subject: Re: Question about scope of "convenience objects"
- From: Scott Ribe <email@hidden>
- Date: Fri, 21 Sep 2007 12:22:36 -0600
- Thread-topic: Question about scope of "convenience objects"
> Actually, -autorelease does not, in any way, add true thread safety to
> an accessor. It only makes it more likely to work by delaying the
> reap of an object a little bit, thus allowing the other thread to -
> retain the object before it is reaped.
Right; I've dealt with that before. I was thinking of the case in which the
parent object is holding a retain on the member which it is returning. There
still must be some synchronization somewhere to ensure that the parent
object is not released from another thread, dealloc'd, and releases the
object to be returned right in the middle of that accessor.
> If you want to "transfer ownership" of an object from one thread to
> another, you *must* retain in the giving thread and *must* either
> preserve that retain in the receiving thread OR retain in the
> receiving thread before releasing *or autoreleasing* in the giving
> thread.
Right; in this accessor the retain & autorelease are both in the "receiving
thread", assuming multiple threads. So this pattern makes sure that the
retain is put on in the receiving thread. Something else must ensure that no
other thread releases in the middle of the accessor--that would often be
implemented with synchronization on at least the dealloc and any such
accessors, but there are other cases.
Sorry to have given an incomplete discussion... Just wanted to point out
that there can be good reasons retain/autorelease/return an object that is
known to be retained.
--
Scott Ribe
email@hidden
http://www.killerbytes.com/
(303) 722-0567 voice
_______________________________________________
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