| |||
| [Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] |
It's also possible to build an example here of why Method 1 (setter does autorelease) could be bad in this situation. Consider, if saveDocument was implemented as:
pool = [[NSAutoreleasePool alloc] init];
...
if (isUntitled) {
...put up save panel, get new name...
[myWindow setRepresentedFilename:newDocumentFileName];
}
...
[pool release];
I am assuming here that setRepresentedFilename: ends up changing the title of the window. In this case, due to the nested autorelease pool, even if the setTitle: method did an autorelease, the value will still be released when "str" is accessed in the outer function.
Hiya Ali,
You must not have had your coffee yet this morning or something. :-)
If the -title method was implemented to be { return [[title retain] autorelease]; }, then the old title has been autoreleased into an _outer_ autorelease pool (probably the default Cocoa pool around handling each event). The fact that another pool is created and destroyed inside -saveDocument is irrelevant. It won't touch the old title, because that isn't the pool that was active when the old title was autoreleased.
I am easily confused early in the morning, but this warning was for "Method 1", which was earlier described to do nothing in the getter...
Ali
| References: | |
| >Re: Accessor methods and (auto)release <Memory trail> (From: Ali Ozer <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.