Skip navigation.
 
mlRe: Cache Class review (low priority)
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

Related mailsAuthorDate
mlCache Class review (low priority) Western Botanicals Apr 30, 15:50
mlRe: Cache Class review (low priority) Jean-Daniel Dupas Apr 30, 16:44
mlRe: Cache Class review (low priority) Jens Alfke Apr 30, 17:08
mlRe: Cache Class review (low priority) Western Botanicals May 1, 00:14
mlRe: Cache Class review (low priority) Jens Alfke May 1, 04:30
mlRe: Cache Class review (low priority) Western Botanicals May 2, 01:49
mlRe: Cache Class review (low priority) Jens Alfke May 2, 06:58
mlRe: Cache Class review (low priority) Gregory Weston May 2, 13:37
mlRe: Cache Class review (low priority) Jens Alfke May 2, 17:22
mlRe: Cache Class review (low priority) Western Botanicals May 2, 18:32
mlRe: Cache Class review (low priority) Jens Alfke May 2, 20:03
mlRe: Cache Class review (low priority) Uli Kusterer May 2, 22:29
mlRe: Cache Class review (low priority) Chris Hanson May 3, 04:24