On Jul 18, 2008, at 2:17 PM, mmalc crawford wrote:
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];
}

I don't see the difference from the caller's point of view. Suppose I have a silly little class that remembers a person's name. Wouldn't I have to retain the return value of -name in this init method?

- (id)initWithPerson:(Person *)person
{
    if ((self = [super init]))
    {
        _name = [[person name] retain];
    }

    return self;
}

I don't know how -name is implemented and I don't care, and I don't know if failing to retain would actually happen to be okay. I only know that I have to retain it to be *sure* it'll stick around.

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.

Okay, when I get a chance I'll dig up the methods that tell us a method returns an autoreleased object.

--Andy

_______________________________________________

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

This email sent to [EMAIL PROTECTED]

Reply via email to