Re: Question about scope of "convenience objects"
Re: Question about scope of "convenience objects"
- Subject: Re: Question about scope of "convenience objects"
- From: Bill Bumgarner <email@hidden>
- Date: Fri, 21 Sep 2007 11:09:51 -0700
On Sep 21, 2007, at 10:04 AM, Scott Ribe wrote:
I see some prefer the style (on a "getter" accessor method) of:
return [[object retain] autorelease];
In an accessor method, that makes sense for objects that might be
shared
between threads. (And I can think of other situations, but they seem
pretty
contrived.) In the context of the current discussion it adds nothing,
because the retain/autorelease of the convenience method must have
been
performed in the current thread.
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.
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.
b.bum
_______________________________________________
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