For code:
int main(int argc, char *argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, nil);
[pool release];
return retVal;
}
Apple's doc clearly specifies:
Return Value: Even though an integer return type is specified, this function never returns. When users terminate an iPhone application by pressing the Home button, the application immediately exits by calling the exit system function with an argument of zero.
Secondly, in int UIApplicationMain ( int argc, char *argv[], NSString *principalClassName, NSString *delegateClassName );
how can we access the argv from our UIApplication subclass?
The autorelease pool doesn't get released. Instead, the OS simply removes your application from memory.
As for the values of argc
and argv
Apple documentation states the following :
NSApplicationMain itself ignores the argc and argv arguments. Instead, Cocoa gets its arguments indirectly via _NSGetArgv, _NSGetArgc, and _NSGetEnviron (see [crt_externs.h]).g
The main autorelease
pool may not get released, but the UIApplicationMain
has an event handler loop which drains it after each event.
As apple documentation states: (Under section iOS section "Allocate Memory Wisely")
Objects released using the autorelease method stay in memory until you explicitly drain the current autorelease pool or until the next time around your event loop.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.