2010-08-27 55 views
2

我有这个在我的main.m:iPhone _NSAutoreleaseNoPool()的问题

printf("make autorelease pool \n"); 
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; 
int retVal = UIApplicationMain(argc, argv, @"UIApplication", @"MyAppDelegate"); 
[pool release]; 
return retVal; 

我突然开始觉得这个时候我在模拟器上运行我的应用程序:

2010-08-27 11:09:35.909 MyApp[6224:207] *** _NSAutoreleaseNoPool(): Object 0x49107c0 of class NSPathStore2 autoreleased with no pool in place - just leaking 

堆栈:( 0xe171f 0x58d64 0x59ebd 0x599ee 0x600c7 0x31d016 0x23198 0x29e94ae 0x29e97c4 0x29ee7c4 0x8fe036c8 0x8fe0d30a 0x8fe0d3d1 0x8fe024a9 0x8fe07950 0x8fe018b1 0x8fe01057)

2010-08-27 11:09:35.911 MyApp的[6224:207] *** _NSA utoreleaseNoPool():对象0x49110c0类NSPathStore2自动释放与地方没有游泳池 - 刚刚泄露 堆栈:(0xe171f 0x58d64 0x5cd69 0x60335 0x601f1 0x31d016 0x23198 0x29e94ae 0x29e97c4 0x29ee7c4 0x8fe036c8 0x8fe0d30a 0x8fe0d3d1 0x8fe024a9 0x8fe07950 0x8fe018b1 0x8fe01057)

2010-08-27 11 :09:35.912 MyApp的[6224:207] *** _NSAutoreleaseNoPool():对象0x4911ce0类NSPathStore2自动释放与地方没有游泳池 - 刚刚泄露 堆栈:(0xe171f 0x58d64 0x6902e 0x445545 0x23198 0x29e94ae 0x29e97c4 0x29ee7c4 0x8fe036c8 0x8fe0d30a 0x8fe0d3d1 0x8fe024a9 0x8fe07950 0x8fe018b1 0x8fe01057 ) 使autorelease池

有没有人有任何想法是什么导致t他? 任何帮助非常感谢!

回答

2

我想我找到了导致它的原因。我有一个方法来加载我的纹理,它的签名看起来像这个+(无效)加载显然,即使你不导入包含任何地方的方法的文件,这应用程序启动时调用。将签名更改为+(void)loadTexture可防止过早调用签名,从而修复“bug”!

对不起回答我自己的问题。我希望这可以节省一些人的时间。

+1

好侦探工作。这是行为的原因:http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSObject_Class/Reference/Reference.html#//apple_ref/doc/uid/20000050-load – 2010-08-27 11:19:00

0

这可能来自没有autorelease池的地方。你必须为每个线程建立一个自己的autorelease池。即使你只是使用NSOperation[NSObject performSelectorInBackground:withObject:],你也必须放置一个自动释放池。

备注:NSAutoreleasePool应该使用其drain方法发布。此方法调用release,在iOS 4等非垃圾收集环境中是等效的。总是使用drain只是一种很好的风格。使用垃圾收集时,它会触发非穷举的收集。

+0

你好尼古拉 谢谢!我想我找到了导致它的原因。我有一种方法来加载我的纹理,它的签名看起来像这样 +(void)加载 显然,即使您不导入包含任何位置的方法的文件,也会在应用程序启动时调用它。 更改签名为 +(void)loadTexture 防止它被过早调用,从而修复“bug”! – 2010-08-27 09:41:36