Re: Memory Management
Re: Memory Management
- Subject: Re: Memory Management
- From: Fritz Anderson <email@hidden>
- Date: Mon, 28 Jul 2003 14:50:50 -0500
On Monday, 28 July 2003, at 1:44 PM, Marcel Weiher wrote:
On Monday, Jul 28, 2003, at 01:20 Europe/London, Martin Haecker wrote:
...
- (NSString *)name
{
return [[_name retain] autorelease];
}
Although there has been some championing of this method by
well-placed individuals, their preference has not met with an
overwhelmingly positive response, to say the least. IMNSHO, their
case, although appealing at first, has been thoroughly debunked and is
not widely supported by the Cocoa community any longer. Of course,
you may disagree with this view, but at the very least the statement
that this is the preferred method is highly controversial.
You surprise me. I once ran into a string-processing method in
OmniFoundation which, in no-op cases, returned its internal storage.
Consider the following code:
NSString * result = [ofProcessingObject processedString];
[ofProcessObject release];
NSLog(@"The result is %@", result);
I am entitled to assume that result has not been disposed-of, am I not?
As it turns out, I'm right in cases where -processString had to
generate its return value (result is an autoreleased NSString), but
wrong when -processString was a no-op (result is an unretained
reference to an NSString member). In the latter cases, result is
invalid at the NSLog.
You will admit that this is a bug in the implementation of
-processedString?
Why, then, is this not a bug:
NSString * result = [myNamedObject name];
[myNamedObject release];
NSLog(@"The name was %@" result); // MPW wants an access exception
here.
You are not allowed to answer that I am _supposed to know_ how -name is
implemented.
Senders of messages with NSObject * replies should be able to assume
that the replies have at least autorelease lifetimes.
-- F
_______________________________________________
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.