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