Re: Newbie: Proper objc style
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.