Re: Cache Class review (low priority)
Re: Cache Class review (low priority)
- Subject: Re: Cache Class review (low priority)
- From: Uli Kusterer <email@hidden>
- Date: Fri, 2 May 2008 22:29:12 +0200
Am 02.05.2008 um 20:03 schrieb Jens Alfke:
You're probably running this as a GUI-less tool process, i.e.
directly calling your code from main(). If you do this, you need to
create a top-level autorelease pool before calling into your code.
In general, main() looks like:
int main( int argc, const char **argv ) {
NSAutoreleasePool *pool = [NSAutoreleasePool new];
int result = 0;
// your program code goes here
[pool drain];
return result;
}
Well, this only shuts up the warnings, it doesn't really keep the
memory from leaking because the pool isn't drained until the app quits.
If you have any sort of loop in your app, you'll want to put the pool
inside that loop, so a new pool gets created and the old pool gets
released for every command you execute.
But don't put the pool inside your accessors or other such small
places. Particularly as generally you want a pool outside a function
when you're returning an object from it, so the pool can temporarily
take ownership of the object after your function has terminated. That
is, if you're not garbage-collected, in which case this doesn't apply.
Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden