On 12/09/2013, at 10:31 PM, Bill Cheeseman <wjcheese...@gmail.com> wrote:

> The Advanced Memory Management Programming Guide I cited earlier says this 
> about the Cocoa ownership rules, which I can't reconcile with your assertion 
> that getters always leave the caller with no responsibility for ownership of 
> the returned object.

> 
> "You can take ownership of an object using retain
> "A received object is normally guaranteed to remain valid within the method 
> it was received in, and that method may also safely return the object to its 
> invoker. You use retain in two situations: (1) In the implementation of an 
> accessor method or an init method, to take ownership of an object you want to 
> store as a property value; and…."

Where this documentation refers to "accessor method" it would appear it's 
referring to the setter, not the getter. I wish they would make those things a 
bit clearer though, but the giveaway is "to take ownership of an object you 
want to store as a property value". That's a setter, not a getter.

This passage otherwise is exactly the documentation that implies that the 
caller does not need to take ownership of the returned object. Of course, it is 
free to do so, but it need not if it's only going to do something with it 
within that method, or pass it back. Within that narrow scope, whether the 
object was [[retain] autoreleased] prior to being passed back makes no 
difference, because nothing could possibly cause it to be deallocated (except 
an explicit, and incorrect -release) while the caller's call stack is being 
executed (we're ignoring threads).

> I wonder if you are perhaps thinking of the Core Foundation Create Rule, 
> which does say that a function named with "get" does not return a retained 
> object (is returned by reference). If you can refer to any Cocoa 
> documentation to the effect that getters never confer ownership in Cocoa, 
> please pass it along.

Definitely no confusion.

The documentation is the one you cited, and by implication getters do not 
contain new, alloc or copy in their names, therefore no ownership is conferred 
by them.

--Graham


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to