| |||
| [Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] |
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
need it.
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.
--Andy
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 IMKInputController instance.
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.
--Andy
_______________________________________________
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: http://lists.apple.com/mailman/options/cocoa-dev/email@hidden
This email sent to email@hidden
_______________________________________________
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: http://lists.apple.com/mailman/options/cocoa-dev/email@hidden
| References: | |
| >NSMutableDictionary autorelease chrashes application (From: Matthias Arndt <email@hidden>) | |
| >Re: NSMutableDictionary autorelease chrashes application (From: Robert Martin <email@hidden>) | |
| >Re: NSMutableDictionary autorelease chrashes application (From: Matthias Arndt <email@hidden>) | |
| >Re: NSMutableDictionary autorelease chrashes application (From: "Shawn Erickson" <email@hidden>) | |
| >Re: NSMutableDictionary autorelease chrashes application (From: "Shawn Erickson" <email@hidden>) | |
| >Re: NSMutableDictionary autorelease chrashes application (From: Andy Lee <email@hidden>) |
| Home | Archives | FAQ | Terms/Conditions | Contact | RSS | Lists | About |
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE
Contact Apple | Terms of Use | Privacy Policy
Copyright © 2007 Apple Inc. All rights reserved.