Re: Is an just allocated object allways set to autorelease? What about my subclasses?
Re: Is an just allocated object allways set to autorelease? What about my subclasses?
- Subject: Re: Is an just allocated object allways set to autorelease? What about my subclasses?
- From: Max Horn <email@hidden>
- Date: Fri, 21 Dec 2001 13:14:10 +0100
At 12:31 Uhr +0100 21.12.2001, Alexandre Aybes wrote:
Hi there,
I am tracking down the (gigantic) memory leaks in my application
(I've been doing too much java for too long ;)) And since I am
fairly new to Cocoa/ObjC and I would like to know if all the basic
Cocoa objects (the ones from the AppKit) are set to autorelease when
I call "[[XXX alloc] init]"
No they are not. Simple rule:
1) if you init+alloc something, or if you copy/mutableCopy something,
you own it and you also have to (auto)release it
2) Everything else is autoreleased. E.g. if you get something from a
factory method like [NSArray array] etc., then it is already
autoreleased
Better covarage of this can be found at
http://www.stepwise.com/Articles/Technical/2001-03-11.01.html and the
new Apple docs on it (in your /Developer folder) are explaining it,
too.
. And another question when I create my own class, should I do:
[...]
or should I do:
- (id)init
{
if (self = [super init])
{
// do my initialization
}
return [self autorelease];
}
No nevr do this!
Max
--
-----------------------------------------------
Max Horn
Software Developer
email: <
mailto:email@hidden>
phone: (+49) 6151-494890