2011-08-15 223 views
-1

我知道還有很多問題需要解決,我試着去關注他們,但我仍然無法弄清楚問題所在。iOS內存管理問題

我已經啓用NSZombiesEnabled,我得到的錯誤信息:

2011-08-15 23:13:12.368 appName[3926:207] *** -[CFString release]: message sent to deallocated instance 0x4cf4570 

如果我在錯誤發生後BT型,我得到這個堆棧跟蹤:

#0 0x00f92657 in ___forwarding___() 
#1 0x00f92522 in __forwarding_prep_0___() 
#2 0x00f3804c in CFRelease() 
#3 0x00f5d18d in _CFAutoreleasePoolPop() 
#4 0x007a53eb in -[NSAutoreleasePool release]() 
#5 0x0004e3ee in _UIApplicationHandleEvent() 
#6 0x0125a992 in PurpleEventCallback() 
#7 0x01002944 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__() 
#8 0x00f62cf7 in __CFRunLoopDoSource1() 
#9 0x00f5ff83 in __CFRunLoopRun() 
#10 0x00f5f840 in CFRunLoopRunSpecific() 
#11 0x00f5f761 in CFRunLoopRunInMode() 
#12 0x012591c4 in GSEventRunModal() 
#13 0x01259289 in GSEventRun() 
#14 0x00051c93 in UIApplicationMain() 
#15 0x00002739 in main (argc=1, argv=0xbfffefd8) at main.m:14 

我假設這條線路正在解釋問題,但我確實不確定:

#7 0x01002944 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__() 

我想我應該在什麼時候釋放物體時會迷路。我試圖在使用alloc,然後在dealloc方法的每個方法的末尾嘗試[object release],我已經發布了該類的所有屬性。

任何人都可以給我一個暗示,我需要做什麼?如有必要,我可以包含更多代碼。

+0

後。的。碼。 – akashivskyy

回答

0

你的應用程序中有一個字符串,你已經發布了。由於autoreleasepool發佈時出現問題,您意外地釋放了一個自動釋放對象。這裏是什麼可能會導致這樣一個例子:

NSString *autoString = [NSString stringWithFormat:@"A formatted string! %d", 0]; 

//use string 

[autoString release];//This will cause a crash about the same place your crash is 

沒有任何相關的代碼,我所能做的是提供作爲模式,爲您尋找在你的代碼的問題。

+0

謝謝。我會看看我能否找到這種模式。我有沒有辦法讓調試器顯示哪個字符串導致崩潰? –

+0

嗯,如果我的方法中使用這個早些時候: '的NSString * thisChar = [[NSString的頁頭] initWithFormat:@ 「」];' 我可以再使用 'thisChar = [NSString的stringWithFormat: @「%C」,tempChar];' 在使用此末端之前 '[thisChar release];' 或者這可能是問題所在? –

+0

這將是你的問題!你需要移動'[thisCar release];'重新分配它或完全移除release,只使用'stringWithFormat:',所以你不要調用alloc,因此不需要釋放。 – Joe