On Jul 18, 2008, at 10:49 AM, Shawn Erickson wrote:
I should more clearly note that objectForKey: is not returning an
"autoreleased" object. Also even if it did it would be an
implementation detail (unless documented in the API docs).
It is returning a reference to an object that the vColors dictionary
has a retained reference to (Cocoa collections retain what you add to
them). At this point in time you have know idea of the lifetime of the
object you get back (it could go away when the vColors dictionary goes
away or it could live longer). If you need something to stay around
outside of the method you are in (assuming no side effects down stream
in that method) then you must retain that object for a long as you
When the docs say a method returns an "autoreleased" object, I assume
it means what you say above about objectForKey:. Otherwise, why
mention it at all? Taken literally, the fact that it is autoreleased
tells us nothing about its life expectancy, and unless I'm missing
something I can't imagine why else I'd care to know.
An Xcode search for "autoreleased" turns up a few cases. For example,
the doc for -[IMKInputController delegate] says "The returned object
is an autoreleased object." So what? We have no idea how many times
the delegate was retained before being assigned to our
Unless Apple defines another adjective for this purpose, it seems to
me that "autoreleased" is a reasonable shorthand for "you must retain
it if you want it to stick around, or you *may* have a dangling
pointer." Similarly, "retained" is a reasonable shorthand for "you
must balance the method you just called with a release, or you'll have
a memory leak."
That said, we do need to understand exactly what is meant when we
speak loosely this way.
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