简体   繁体   English

如果UIApplicationMain()永远不会返回,那么自动释放池何时被释放?

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

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: Apple的文档明确指出:

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. 当用户通过按Home键终止iPhone应用程序时,应用程序会立即通过调用退出系统函数退出,参数为零。

Secondly, in int UIApplicationMain ( int argc, char *argv[], NSString *principalClassName, NSString *delegateClassName ); 其次,在int UIApplicationMain ( int argc, char *argv[], NSString *principalClassName, NSString *delegateClassName ); how can we access the argv from our UIApplication subclass? 我们如何从UIApplication子类访问argv?

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 : 至于argcargv的值,Apple文档说明如下:

NSApplicationMain itself ignores the argc and argv arguments. NSApplicationMain本身忽略了argc和argv参数。 Instead, Cocoa gets its arguments indirectly via _NSGetArgv, _NSGetArgc, and _NSGetEnviron (see [crt_externs.h]).g 相反,Cocoa通过_NSGetArgv,_NSGetArgc和_NSGetEnviron间接获取其参数(参见[crt_externs.h])。

The main autorelease pool may not get released, but the UIApplicationMain has an event handler loop which drains it after each event. autorelease池可能不会被释放,但UIApplicationMain有一个事件处理程序循环,在每个事件之后将其排出。

As apple documentation states: (Under section iOS section "Allocate Memory Wisely") 正如苹果文档所述:(在iOS部分“明确分配内存”部分)

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. 使用autorelease方法释放的对象将保留在内存中,直到您明确地耗尽当前自动释放池或直到下一次事件循环为止。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM