• 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: Question about scope of "convenience objects"
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Question about scope of "convenience objects"
      • From: Scott Ribe <email@hidden>
References: 
 >Re: Question about scope of "convenience objects" (From: Scott Ribe <email@hidden>)

  • Prev by Date: Re: really weird move file problem
  • Next by Date: Re: Question about scope of "convenience objects"
  • Previous by thread: Re: Question about scope of "convenience objects"
  • Next by thread: Re: Question about scope of "convenience objects"
  • Index(es):
    • Date
    • Thread