Re: Accessor methods and (auto)release <Memory trail>
Re: Accessor methods and (auto)release <Memory trail>
- Subject: Re: Accessor methods and (auto)release <Memory trail>
- From: Greg Titus <email@hidden>
- Date: Wed, 31 Jul 2002 11:23:11 -0700
On Wednesday, July 31, 2002, at 11:16 AM, Ali Ozer wrote:
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
Ah. My apologies. I must have misread setter as getter....
-Greg
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.