Re: new to memory mgmt
Re: new to memory mgmt
- Subject: Re: new to memory mgmt
- From: pmcurry <email@hidden>
- Date: Sun, 15 Feb 2004 12:42:44 -0800
I thought I had read somewhere that NSAutoreleasePools were expensive
so I've been trying to only use them in a situation where I create an
object within a function that I want to use as the return value. Then I
create a pool in the function and auto release the object just before
returning it. In your example, how can you tell at what point execution
goes back to NSApplicationMain()?
Thanks for the quick feedback.
-Phil
On Feb 15, 2004, at 12:29 PM, Troy Dawson wrote:
On Feb 15, 2004, at 12:04 PM, pmcurry wrote:
Just looking for some reassurance that I'm starting to understand
some parts of memory mgmt.
Code fragment:
switch ( message ) {
<snip>
case: kBegin
Node n = [[Node alloc] init];
[n setRank:a];
[n setParent:b];
[n setState:c];
[tree addObject:n]
[n release];
yes, that is correct.
IMO, what you can do to make it [more] clear that you are just
releasing the local retain of the object is to do this instead:
[tree addObject: [n autorelease]];
the autorelease defers any dealloc of the object (if the refcount is
0) until the thread's execution goes back into NSApplicationMain().
But this is just a style thing and not that important.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.