• 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: [[myObj retain] autorelease]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [[myObj retain] autorelease]


  • Subject: Re: [[myObj retain] autorelease]
  • From: Charilaos Skiadas <email@hidden>
  • Date: Tue, 12 Jul 2005 14:47:48 -0500

On Jul 12, 2005, at 2:32 PM, Ben Kazez wrote:

Sorry to ask a question about a topic that appears so frequently, but here I go: I haven't been able to find anything that explains when to use

   return [[myObj retain] autorelease];

instead of just

   return [myObj autorelease];

For example, Apple's default accessor methods do this. Is the reasoning something to do with thread-safeness perhaps?

Those forms do not refer to the same thing. What you should be comparing is:


    return myObj;

versus

    return [[myobj retain] autorelease];

There were long discussions at some point as to which of the two is the proper form for a getter, so you can find lots of discussions in the archives. There is a long thread worth reading here:
http://cocoa.mamasam.com/COCOADEV/2002/08/1/41613.php



The second form you refer to above is simply used when the method has created myObj, and needs to release it but at the same time return it, and make sure it does not get deallocated before whoever called the method has the time to handle it. This is ASAICT the typical use of an autorelease.
Ben

Haris


_______________________________________________ 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
  • Follow-Ups:
    • Re: [[myObj retain] autorelease]
      • From: Ben Kazez <email@hidden>
References: 
 >[[myObj retain] autorelease] (From: Ben Kazez <email@hidden>)

  • Prev by Date: Re: [[myObj retain] autorelease]
  • Next by Date: Re: TableView Mouse Tracking problem
  • Previous by thread: Re: [[myObj retain] autorelease]
  • Next by thread: Re: [[myObj retain] autorelease]
  • Index(es):
    • Date
    • Thread