See also When does autorelease release ?

Calling autorelease on an object will call that object to be release d just after the current run loop has finished running the current event, for example after your mouseDown returns control back to the runtime. That way, autoreleased objects get killed quickly.

BUT creating a “top level” autorelease pool in main.m before NSApplicationMain starts will cause objects to be released after NSApplicationMain returns, that is when your application quits and you release the pool you created.

int main(int argc, char *argv[]) { // Create our pool id pool = [[NSAutoreleasePool alloc] init]; // Call some code that will alloc and autorelease objects ... // Run app int r = NSApplicationMain(argc, (const char **) argv); // Release our pool : objects allocated and autoreleased before NSApplicationMain will get killed here [pool release]; return r; }

This can be problematic if you want your objects to be released sooner. Luckily, we can create and destroy autorelease pools whenever we want, so we can release that first pool as long as we keep a global reference to it.

@implementation MyAutoreleasePool static id autoreleasePool; + (void)allocAutoreleasePool { autoreleasePool = [[NSAutoreleasePool alloc] init]; } + (void)deallocAutoreleasePool { [autoreleasePool release]; } @end

[MyAutoreleasePool allocAutoreleasePool]

main.m

[MyAutoreleasePool deallocAutoreleasePool]

awakeFromNib

Callin, then callin (for example) the application delegate's. You'll then need to create a new autorelease pool, and that one will behave like you expect : killing objects on time.