• 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: Newbie: Proper objc style
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Newbie: Proper objc style


  • Subject: Re: Newbie: Proper objc style
  • From: mmalcolm crawford <email@hidden>
  • Date: Mon, 10 May 2004 01:08:11 -0700

On May 10, 2004, at 12:51 AM, Ondra Cada wrote:
On 10.5.2004, at 7:31, mmalcolm crawford wrote:

By conventionally, however, objects should always be returned autoreleased unless otherwise documented
Correct me please if I am wrong, but I believe that this is not the convention: unless I've missed something important, the convention says just the following:
it is the responsibility of the method caller to retain them if they want

which effectively means the returned object can be either autoreleased, OR shared (a singleton), OR whatever (e.g., if it makes sense in a particular case, the vendor may keep track of vended objects and release them when some special conditions are met).
The only invariant is that the receiving code is not assumed to release the object (unless it retained it).

Mea culpa, that was sloppily put -- thank you for picking this up.

In the context of returning a collection of new objects, as is the case here, we can reasonably approximate the convention to be that the array will be autoreleased. Nevertheless it would have been better to put is, as you did, "it is the responsibility of the method caller to retain them if they want". It would have been better still had I adhered to my own maxim and simply pointed to the relevant documentation. (This is a perfect example of why I advocate referencing the existing articles -- if you try to be brief or approximate, you get details wrong.)

The means of achieving that can differ and are not fixed anyhow; vending an autoreleased object is just the most common one, but by far not the only one.

Indeed.

For memory management articles, see:
<http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/ Concepts/ObjectOwnership.html>
<http://www.stepwise.com/Articles/Technical/2001-03-11.01.html>
<http://www.stepwise.com/Articles/Technical/HoldMe.html>
<http://cocoadevcentral.com/articles/000055.php>
<http://www.macdevcenter.com/pub/a/mac/2001/07/27/cocoa.html>
<http://www.stepwise.com/Articles/Technical/2002-06-11.01.html>

mmalc
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


  • Follow-Ups:
    • Re: Newbie: Proper objc style
      • From: "David W. Halliday" <email@hidden>
References: 
 >Newbie: Proper objc style (From: Jorge Martins <email@hidden>)
 >Re: Newbie: Proper objc style (From: mmalcolm crawford <email@hidden>)
 >Re: Newbie: Proper objc style (From: Jorge Martins <email@hidden>)
 >Re: Newbie: Proper objc style (From: mmalcolm crawford <email@hidden>)
 >Re: Newbie: Proper objc style (From: Ondra Cada <email@hidden>)

  • Prev by Date: Re: Newbie: Proper objc style
  • Next by Date: Re: Custom Frameworks, building and using
  • Previous by thread: Re: Newbie: Proper objc style
  • Next by thread: Re: Newbie: Proper objc style
  • Index(es):
    • Date
    • Thread