0
__NSAutoreleaseNoPool(): Object 0x4c70ec0 of class UISegmentedControl autoreleased with no pool in place - just leaking 
__NSAutoreleaseNoPool(): Object 0x4c70ec0 of class UISegmentedControl autoreleased with no pool in place - just leaking 
__NSAutoreleaseNoPool(): Object 0x4c70ec0 of class UISegmentedControl autoreleased with no pool in place - just leaking 
__NSAutoreleaseNoPool(): Object 0x4c70ec0 of class UISegmentedControl autoreleased with no pool in place - just leaking 
__NSAutoreleaseNoPool(): Object 0x4c70ec0 of class UISegmentedControl autoreleased with no pool in place - just leaking 

这是我在控制台中得到的警告。虽然它不会造成崩溃,但似乎是一些内存管理问题。NSAutoreleasepool:iPhone应用程序中的内存管理问题

什么可能是错的?

我还没有autoreleased我的segemented控制。

+1

您是在main.m中还是在并行进程中创建控件? – mackworth 2011-02-28 06:06:14

+0

你将需要发布一些代码 – Bogatyr 2011-02-28 06:07:34

回答

7

当您使用多线程时,通常会出现此问题。 如果你使用线程,应为该线程

 
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 

//Code.... 

[pool release]; 
+0

哪些代码应该写在'NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];'''[pool release]'? – 2011-02-28 08:24:55

+0

你在线程中运行的函数或任何代码(如果它不在主线程中,主线程有默认的自动释放池,如果你在你的项目中打开main.m,你可以看到这个。)应该有自动释放池。 – itZme 2011-02-28 09:15:51

+0

谢谢马丁。它为我工作非常感谢:] – 2011-03-05 12:28:20

0

创建自动释放池,如果在一个线程是不是主线程作为@马丁说使用UISegmentedControl,它是不是安全。

UIKit Framework Reference - Introduction

注:在大多数情况下,UIKit类 应该仅仅从 应用程序的主线程中使用。这是 尤其适用于来自UIResponder的衍生 或涉及 以任何方式操纵应用程序的用户 接口。

+0

我在我的线程中使用活动指标和UILabel。这可能是一个原因吗?如果是,那么解决这个问题的方法是什么? – 2011-02-28 08:29:35

+0

使用NSObject -performSelectorOnMainThread:withObject:waitUntilDone或Grand Central Dispatch Main Queue进行活动指示器和UILabel操作。 – 2011-02-28 08:33:34