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: Alexandre Aybes <email@hidden>
- Date: Fri, 21 Dec 2001 13:19:27 +0100
Thanks Max,
This list is great, whatever time of the day (and in the world)
you post you always get a reply fast, because of the people
worldwide :)
On Friday, December 21, 2001, at 01:14 , Max Horn wrote:
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
Ohhh... okay makes sense that way.
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.
I'll go read that article :)
or should I do:
- (id)init
{
if (self = [super init])
{
// do my initialization
}
return [self autorelease];
}
No nevr do this!
You know what I had just tried it and got a good old SIGBUS :)
And is sounded weird to me too...
Thanks!
Alex.