XCode4設定不太一樣: 在Edit–>Scheme裡面 找到Arguments(在xcode 4.2中,在菜單 product->edit scheme中)
把下面3個值設定成YES
NSAutoreleaseFreedObjectCheckEnabled
NSZombieEnabled
NSDebugEnabled
另外轉載2篇調試EXC_BAD_ACCESS的好文http://blog.zol.com.cn/2387/article_2386505.html
http://www.cnblogs.com/likwo/archive/2011/02/28/1967066.html
老外也有這麼說的:I had similar issue; turns out I was
not retaining a UIButton properly. How I found the cause: - Enable zombies - Run the project with 'Allocations' instrument - Use the app to trigger the bug - Check that Instruments show message 'Zombie Messaged' on the timeline - There should be a link that
opens CALayer details: when it was allocated and deallocated - You are interested in the place where is was allocated, should be that aha!!! place in your code
我是用模擬器上 使用zombies,然後運行程式,崩潰的時候會有提示崩潰點,同時有代碼。
轉另一個人文章:
方法一:
PAEHoldTranMainControl *control = [[PAEHoldTranMainControl alloc]init];
[self.navigationController pushViewController:control animated:YES];
[control release];
alloc了一個control,release,運行就崩潰了。而且沒有任何提示,console裡只顯示exc_bad_access
利用NSZombieEnabled參數,MallocStackLogging參數,顯示 -[CALayer release]: message sent to deallocated instance 0x13570810
折騰了半天,最後用如下方法定位問題:
開啟instrument-->ios simulator:
選擇all--》 zombies運行,斷開時,查看stack trace,即可跟蹤
方法二:例如console裡的輸出如下:
TestAPP[1472:207] *** -[NSObject release]: message sent to deallocated instance 0x6019170
在 gdb console 裡面, 運行 shell malloc_history <pid> <mem_address>
pid = process ID (e.g. 1472)
mem_address = memory address of instance (e.g. 0x6019170)
即會出現調用棧