Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If the UIApplicationMain() never returns then when does the autorelease pool gets released?

Tags:

cocoa

iphone

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?

like image 367
chunkyguy Avatar asked Dec 13 '22 22:12

chunkyguy


2 Answers

The autorelease pool doesn't get released. Instead, the OS simply removes your application from memory.

like image 132
Dietrich Epp Avatar answered Jan 18 '23 14:01

Dietrich Epp


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

like image 25
Navi Sidhu Avatar answered Jan 18 '23 14:01

Navi Sidhu