Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSMutableDictionary autorelease chrashes application



On Jul 18, 2008, at 1:20 PM, Andy Lee wrote:
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."

"Autoreleased" is inaccurate and is not a proper shorthand for "you must retain it if you want it to stick around".
To understand why, consider two possible implementations of a get accessor:


- (NSString *)name {
    return name;
}

- (NSString *)name {
    return [[name retain] autorelease];
}

...


It is typically better to talk in terms of ownership (see <http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/Tasks/MemoryManagementRules.html >).




On Jul 18, 2008, at 10:48 AM, Andy Lee wrote:

And come to think of it, why mention that method X returns an object- I-need-to-retain, but not mention it for method Y? If it's assumed I've read the memory management rules, these should go without saying. So maybe I am missing something.

In general, the documentation should not make any statements about memory management unless (in very rare circumstances) a method breaks the basic rules or where clarification may be deemed appropriate (e.g. <http://developer.apple.com/documentation/Cocoa/Reference/CoreDataFramework/Classes/NSEntityDescription_Class/Reference/NSEntityDescription.html#//apple_ref/occ/clm/NSEntityDescription/insertNewObjectForEntityForName:inManagedObjectContext: >.

If you find cases where memory management is mentioned simply to state that a method follows the standard rules, please file a bug or send in feedback using the form in the documentation.

mmalc

_______________________________________________

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
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>)
 >Re: NSMutableDictionary autorelease chrashes application (From: Andy Lee <email@hidden>)



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.