Objective c 为什么在执行之后;[泳池排水管]”;,它永远不会回到来电者那里?
这是我的代码模板:Objective c 为什么在执行之后;[泳池排水管]”;,它永远不会回到来电者那里?,objective-c,cocoa,gnustep,Objective C,Cocoa,Gnustep,这是我的代码模板: int main(int argc, char *argv[]) { // create an autorelease pool NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; // make sure the application singleton has been instantiated NSApplication * application = [NSAppl
int main(int argc, char *argv[]) {
// create an autorelease pool
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
// make sure the application singleton has been instantiated
NSApplication * application = [NSApplication sharedApplication];
// instantiate our application delegate
AppDelegate * applicationDelegate =
[[[AppDelegate alloc] init] autorelease];
// assign our delegate to the NSApplication
[application setDelegate:applicationDelegate];
// call the run method of our application
[application run];
// drain the autorelease pool
[pool drain];
// execution never gets here ..
return 0;
}
“[pool drain]”后跟“return 0”为什么从未执行
但是,我发现了另一个gnustep官方示例,它也做了同样的事情
int
main(int argc, char **argv, char** env)
{
id pool = [NSAutoreleasePool new];
NSApplication *theApp;
#if LIB_FOUNDATION_LIBRARY
[NSProcessInfo initializeWithArguments:argv count:argc environment:env];
#endif
theApp = [NSApplication sharedApplication];
[theApp setDelegate: [browserController new]];
[theApp run];
[pool release];
return 0;
}
为了证明“[theApp run]”永远不会返回,我在“[theApp run]”之后添加了一个无限循环,但它永远不会执行。为什么GNUSTEP官方的示例会这样做?您确定
[pool drain]
实际上也会被调用吗<除非调用[NSApp stop]
,否则code>[application run]不会返回(这种情况很少见)。如果调用更常见的[NSApp terminate]
,如下所示:
不要费心在应用程序的main()中放入最终清理代码
它永远不会被执行。如果需要清理,请执行以下操作:
代理的应用程序中的清理将终止:方法
一旦您将应用程序移交给
运行
,您通常不会将其取回。您确定[pool drain]
实际上也会被调用吗<除非调用[NSApp stop]
,否则code>[application run]不会返回(这种情况很少见)。如果调用更常见的[NSApp terminate]
,如下所示:
不要费心在应用程序的main()中放入最终清理代码
它永远不会被执行。如果需要清理,请执行以下操作:
代理的应用程序中的清理将终止:方法
一旦你将应用程序交给
运行
,你通常就无法将其取回。我查看了stackoverlow上与我的问题相关的过去文章。它说很久以前就有虫子存在了。我不确定你在这里是什么意思。没有虫子。它的行为如文档所示-run不一定会回来。我查看了stackoverlow上与我的问题相关的过去帖子。它说很久以前就有虫子存在了。我不确定你在这里是什么意思。没有虫子。它的行为如文档所示-run不保证返回。