• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Is an just allocated object allways set to autorelease? What about my subclasses?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Is an just allocated object allways set to autorelease? What about my subclasses?
      • From: Alexandre Aybes <email@hidden>
References: 
 >Is an just allocated object allways set to autorelease? What about my subclasses? (From: Alexandre Aybes <email@hidden>)

  • Prev by Date: row bg color in NSOutlineView
  • Next by Date: Re: Is an just allocated object allways set to autorelease? What about my subclasses?
  • Previous by thread: Is an just allocated object allways set to autorelease? What about my subclasses?
  • Next by thread: Re: Is an just allocated object allways set to autorelease? What about my subclasses?
  • Index(es):
    • Date
    • Thread