Question

I am having doubts on when an autoreleased object. WHen I found this question,

In the thread's accepted answer, the below explanation is provided for the runloop execution:

void int UIApplicationMain (int argc, char *argv[], NSString *principalClassName, NSString *delegateClassName) {
    UIApplication *app = /* create app using principalClassName */;
    [app setDelegate:/* create delegate using delegateClassName */];
    while (![app shouldTerminate]) {
        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
        event = [app getNextEvent];
        [app dispatchEvent:event];
        [pool drain];
    }
}

Is this how runloop execution occurs?

And does it mean on each execution of runloop, a new autorelease pool will be created and released.

Was it helpful?

Solution

Yes. Each loop there you are creating a new pool, and destroying it.

This explains how drain in a reference-counted environment, is equivalent to release, so it is destroyed. Next loop, you alloc, init another.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top