Reputation: 12231
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.
Upvotes: 2
Views: 223
Reputation: 2752
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.
Upvotes: 4