在xcode4.0中选择edit scheme
-》arguments-》在下一个框也就是environment
variables添加两个变量:NSZombieEnabled、MallocStackLogging
并都设置成yes
并勾选上
然后在调试程序,在xcode底部的控制台中会输出:
2011-12-15 15:11:55.631 Tmart[846:207] ***
-[OrderViewController respondsToSelector:]: message sent to
deallocated instance 0x538b810
(gdb) shell malloc_history 846 0x538b810
malloc_history Report Version: 2.0
Process:
Tmart [846]
Path:
/Users/heql/Library/Application Support/iPhone
Simulator/4.3.2/Applications/EB266964-AE73-4DF5-BE99-9D4F83637AAA/Tmart.app/Tmart
Load Address:
0x1000
Identifier:
Tmart
Version:
??? (???)
Code Type:
X86 (Native)
Parent Process: gdb-i386-apple-darwin
[848]
Date/Time:
2011-12-15 15:12:41.994 +0800
OS Version:
Mac OS X 10.6.6 (10J567)
Report Version: 7
ALLOC 0x538b810-0x538b8bb [size=172]: thread_a00a8540 |start |
main | UIApplicationMain | GSEventRun | GSEventRunModal |
CFRunLoopRunInMode | CFRunLoopRunSpecific | __CFRunLoopRun |
__CFRunLoopDoSource1 |
__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ |
PurpleEventCallback | _UIApplicationHandleEvent | -[UIApplication
sendEvent:] | -[UIWindow _sendTouchesForEvent:] | -[UIControl
touchesEnded:withEvent:] | -[UIControl(Internal)
_sendActionsForEvents:withEvent:] | -[UIControl
sendAction:to:forEvent:] | -[UIApplication
sendAction:to:from:forEvent:] | -[CartViewControler goCheckout] |
+[NSObject(NSObject) alloc] | +[NSObject(NSObject) allocWithZone:]
| class_createInstance | calloc |
malloc_zone_calloc
由此大概判断错误的位置,完事之后 将那两个变量取消勾选
再加点吧,貌似跟我写的有点不同,以后再详细看看:
xcode4 4.x
EXC_BAD_ACCESS这个问题一直不好调试,之前有看到过说配置一个环境变量可以很方便的跟踪问题,因此试了一下,发现还真是方便了很多,以下是XCODE 4的配置方法:
Edit Scheme->Arguments->Environment variables
增加 NSZombieEnabled ,设置为YES,并勾选上,OK,再次运行,在console就会显示出出错的地方了.
(另外:
NSLog(@"id :
像这样的语句也会引起EXC_BAD_ACCESS,大家要注意了哦
)