Re: [[object autorelease] release]
Re: [[object autorelease] release]
- Subject: Re: [[object autorelease] release]
- From: "Sven A. Schmidt" <email@hidden>
- Date: Tue, 2 Oct 2001 00:24:16 +0200
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 ];
}
where one balances the retain with a release before the former actually
gets send. I thought they said it's safe not to protect the
[ number release ]
with an
if ( number )
for that reason.
What about that? Or does it crash when the autorelease tries to delete
the now already manually released object?
Sven