FROM : Uli Kusterer
DATE : Fri May 02 22:29:12 2008
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
DATE : Fri May 02 22:29:12 2008
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
| Related mails | Author | Date |
|---|---|---|
| Western Botanicals | Apr 30, 15:50 | |
| Jean-Daniel Dupas | Apr 30, 16:44 | |
| Jens Alfke | Apr 30, 17:08 | |
| Western Botanicals | May 1, 00:14 | |
| Jens Alfke | May 1, 04:30 | |
| Western Botanicals | May 2, 01:49 | |
| Jens Alfke | May 2, 06:58 | |
| Gregory Weston | May 2, 13:37 | |
| Jens Alfke | May 2, 17:22 | |
| Western Botanicals | May 2, 18:32 | |
| Jens Alfke | May 2, 20:03 | |
| Uli Kusterer | May 2, 22:29 | |
| Chris Hanson | May 3, 04:24 |






Cocoa mail archive

