http://stackoverflow.com/questions/327082/exc-bad-access-signal-received
A major cause of EXEC_BAD_ACCESS is from trying to access release objects.
To find out how to troubleshoot this, read this document: DebuggingAutoReleasePool
Even if you don't think you are "releasing auto-released objects", this will apply to you.
This method works extremely well. I use it all the time with great success!!
In summary, this explains how to use Cocoa's NSZombie debugging class and the command line "malloc_history" tool to find exactly what released object has been accessed in your code.
Sidenote:
Running Instruments and checking for leaks will not help troubleshoot EXEC_BAD_ACCESS. I'm pretty sure memory leaks have nothing to do with EXEC_BAD_ACCESS. The definition of a leak is an object that you no longer have access to, and you therefore cannot call it.
http://www.cocoadev.com/index.pl?DebuggingAutorelease
http://www.cnblogs.com/mac_arthur/archive/2010/04/09/1708364.html
debug-exc_bad_access-on-iphone
當程式出現“EXC_BAD_ACCESS”時,就像不解風情的妻子對你說:“親愛的,今晚不行”。這兩種情況都是非常不幸的。
讓我們先看看EXC_BAD_ACCESS到底是什麼。
向已經釋放的對象發送消息時會出現EXC_BAD_ACCESS。當出現錯誤時,通常會調用堆棧資訊,特别是在多線程的情況下。
怎樣提供一個dummy,當釋放一個對象導緻程式終止時,在堆棧上告訴我們錯誤資訊,好,下面我們将告訴你怎麼去做。
如果你設定了NSZombiEnabled環境變量,當銷毀一個對象時,objective的運作時環境會在這個對象後邊設定一個dummy,當 調用這個對象的方法時,程式會終止,并在堆棧上顯示錯誤資訊,下邊教你怎麼設定NSZombiEnabled
首先,在Xcode中打開executables
檢視其中内容的資訊。
然後,打開資訊面闆中的Arguments面闆
點選左下角的加号,添加變量NSZombiEnabled,并将變量的值設定為YES。
重新運作程式,當過度釋放對象時,會在控制台上出現如下資訊:
2009-03-30 02:30:36.172 ninjaJumper[3997:20b] *** -[GameLayer retain]: message sent
to deallocated instance 0x59bf670
說明想GameLayer的一個對象發送了retain消息
檢視堆棧資訊:
如何檢視:http://lovebirdegg.javaeye.com/blog/550489
當問題解決後,要将NSZombieEnabled設定為無效,不需要删除變量,将變量前的對号去掉就可以了:
設定Global Breakpoint定位錯誤代碼所在位置
文章分類:移動開發 調式程式的時候經常為了出了錯誤而不知道原因在哪頭疼,可以通過設定XCode的Global Breakpoint快速定位錯誤代碼的位置
步驟一:
Run–>Show–>Breakpoints,進入斷點視窗
步驟二:
為-[NSException raise]設定斷點
選擇Global Breakpoints, 輕按兩下Double-click for Symbol, 輸入-[NSException raise],然後按回車。
步驟三:
按照上面的步驟添加objc_exception_throw
以上步驟做完,程式出錯的時候就可以定位到問題代碼了
當程式出現問題時打開Debugger畫面:
點選控制台左邊那個按鈕,或Run->Debugger會出現如下畫面:
在左上角的視窗下出錯的方法會加黑,如 -[PlayGameViewController gameloop]
單擊加黑的方法,程式就回跳轉到出錯的位置