Re: [[object autorelease] release]
Re: [[object autorelease] release]
- Subject: Re: [[object autorelease] release]
- From: Andrew Pinski <email@hidden>
- Date: Mon, 1 Oct 2001 18:35:59 -0400
On Monday, October 1, 2001, at 06:24 PM, Sven A. Schmidt wrote:
On Montag, Oktober 1, 2001, at 09:29 Uhr, Markus Hitter wrote:
You all might remeber the current discussion "Does Cocoa just leak?"
What I don't understand until today is: Why can't you explicitely
release an autoreleased object? I think this could be a big
performance win in some situations.
Something like:
for (i=0; i<100000; i++) {
myString = [NSString stringWithString:@"Hello"];
[myString doSomething];
[myString release]; // not allowed btw. crashes
}
Wait a minute, I recall reading somewhere (I think it was on stepwise)
that it's all right to send a release message to nil. I think it was in
something like
-(void) setNumber: (NSNumber)value {
[ number release ];
number = [ value retain ];
}
One thing I would do is
-(void) setNumber: (NSNumber)value
{
[value retain];
[number release];
number = value;
}
Just in case number = value and the reference count is only one, which
can happen(i.e. [self setNumber: number]).
Thanks
Andrew Pinski