xCode4设置NSZombieEnabled

今天看到偶然间看到一篇blog,“ 用NSZombieEnabled解决恼人的EXC_BAD_ACCESS错误 ”。
很实用的技巧,便拿来试验一下。
原文是在XCode3里面设置的,so在4里面完全找不到地方。stackoverflow搜一下,找到如下方法。
菜单里Product->EditScheme->Run->EnvironmentVariables, 添加NSZombieEnabled,YES。

顺便发现方法2,Product->按住alt/option+鼠标点"Run...",之后同上。
如果你和我一样操作了,一定发现了:按下alt/option键之后菜单边了,同理,按下Ctrl键之后菜单也变了。
神奇ing!
顺便在Navigate看到一条”Fix nextissue“,(按住Ctrl),原来XCode支持 自动修复简单错误
试验发现只要报错信息里有fix方法的,都能用Ctrl+Command+'修复。


In the Xcode IDE two environment variables are useful for gettingfurther information on the memory allocation error EXC_BAD_ACCESSwhen using the simulator: 

NSZombieEnabled=YES
MallocStackLoggingNoCompact=1


There variables should be unchecked when not debugging specificmemory issues, as they will cause the memory shortages in theruntime environment, and should never be enabled in a shippingapplication. This is indicated by the followingmessage: 

"Data Formatters temporarily unavailable, will re-try after a'continue'. (Not safe to call dlopen at thistime.)" 

Uncheck these environment variables to resolve the issue.

Resolution

To set these environment variables in the XcodeIDE. 

In Xcode 3.2: 
- In the left pane of Xcodeexpand  Executables 
- Select the application executable 
-Select  File  GetInfo 
- Selectthe  Arguments  segmentcontrol 
- At the bottom of the  Variables to be setin the environment  dialogueclick  + 
-Enter  NSZombieEnable  forthe nameand  YES  for thevalue 
-Click  +  again 
-Enter  MallocStackLoggingNoCompact  forthe nameand  1  for thevalue 
- Close the dialogue 

In Xcode 4.0: 
-Select  Product  EditScheme  from themenu 
- Select the appropriate scheme ( Run/Test) in theleft pane 
- Selectthe  Arguments  segmentcontrol 
- At the bottom of the  EnvironmentVariables  dialogueclick  + 
-Enter  NSZombieEnable  forthe nameand  YES  for thevalue 
-Click  +  again 
-Enter  MallocStackLoggingNoCompact  forthe nameand  1  for thevalue 
- Close the dialogue 

Recreate the fault. An error should appear in the debugger console( Run  Console). 
*** -[__NSArrayI release]: message sent to deallocated instance 0x4d90af0


This address is then used to query the debuggerwith  infomalloc-history
(gdb) info malloc-history 0x4d90af0 (注:只能在模拟器上使用)


That will produce the following output: 
Alloc: Block address: 0x04d90af0 length: 32
Stack - pthread: 0xa0078540 number of frames: 37
    0: 0x90e5a103 in malloc_zone_calloc
    1: 0x5d862 in NSAllocateScannedUncollectable
    2: 0xa659b in _NSInitializeCacheLine
    3: 0xa6318 in _sortedObjectsUsingDescriptors
    4: 0x127c89 in -[NSSet(NSKeyValueSorting) sortedArrayUsingDescriptors:]
    5: 0x24b0d in -[Task getFullSession:intoArray:] at /Application/Task.m:177
    6: 0x604d in -[AViewController viewDidLoad] at /Application/Classes/AViewController.m:50
    7: 0x3a965e in -[UIViewController view]
    8: 0x3a7a57 in -[UIViewController contentScrollView]
    9: 0x3b8201 in -[UINavigationController _computeAndApplyScrollContentInsetDeltaForViewController:]
   10: 0x3b6831 in -[UINavigationController _layoutViewController:]
   11: 0x3b7b4c in -[UINavigationController _startTransition:fromViewController:toViewController:]
   12: 0x3b2606 in -[UINavigationController _startDeferredTransitionIfNeeded]
   13: 0x4cae01 in -[UILayoutContainerView layoutSubviews]
   14: 0x1e87451 in -[CALayer layoutSublayers]
   15: 0x1e8717c in CALayerLayoutIfNeeded
   16: 0x1e87088 in -[CALayer layoutIfNeeded]
   17: 0x3aab5f in -[UIViewController window:willAnimateRotationToInterfaceOrientation:duration:]
   18: 0x3238e9 in -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:]
   19: 0x5a2948 in -[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:]
   20: 0x3ad982 in -[UIViewController presentModalViewController:withTransition:]
   21: 0x3a6269 in -[UIViewController _tryRecursivelyPresentModalViewController:withTransition:]
   22: 0x3ad085 in -[UIViewController presentModalViewController:withTransition:]
   23: 0x4bc0 in -[RootViewController tableView:didSelectRowAtIndexPath:] at /Application/Classes/RootViewController.m:98
   24: 0x371794 in -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:]
   25: 0x367d50 in -[UITableView _userSelectRowAtPendingSelectionIndexPath:]
   26: 0x7a7f6 in __NSFireDelayedPerform
   27: 0x128afe3 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__
   28: 0x128c594 in __CFRunLoopDoTimer
   29: 0x11e8cc9 in __CFRunLoopRun
   30: 0x11e8240 in CFRunLoopRunSpecific
   31: 0x11e8161 in CFRunLoopRunInMode
   32: 0x1ae9268 in GSEventRunModal
   33: 0x1ae932d in GSEventRun
   34: 0x30a42e in UIApplicationMain
   35: 0x2914 in main at /Application/main.m:14
   36: 0x28a5 in start
Dealloc: Block address: 0x04d90af0
Stack - pthread: 0xa0078540 number of frames: 35
    0: 0x90e5e1ad in malloc_zone_free
    1: 0xa64bb in _sortedObjectsUsingDescriptors
    2: 0x127c89 in -[NSSet(NSKeyValueSorting) sortedArrayUsingDescriptors:]
    3: 0x24b0d in -[Task getFullSession:intoArray:] at /Application/Task.m:177
    4: 0x604d in -[AViewController viewDidLoad] at /Application/Classes/AViewController.m:50
    5: 0x3a965e in -[UIViewController view]
    6: 0x3a7a57 in -[UIViewController contentScrollView]
    7: 0x3b8201 in -[UINavigationController _computeAndApplyScrollContentInsetDeltaForViewController:]
    8: 0x3b6831 in -[UINavigationController _layoutViewController:]
    9: 0x3b7b4c in -[UINavigationController _startTransition:fromViewController:toViewController:]
   10: 0x3b2606 in -[UINavigationController _startDeferredTransitionIfNeeded]
   11: 0x4cae01 in -[UILayoutContainerView layoutSubviews]
   12: 0x1e87451 in -[CALayer layoutSublayers]
   13: 0x1e8717c in CALayerLayoutIfNeeded
   14: 0x1e87088 in -[CALayer layoutIfNeeded]
   15: 0x3aab5f in -[UIViewController window:willAnimateRotationToInterfaceOrientation:duration:]
   16: 0x3238e9 in -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:]
   17: 0x5a2948 in -[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:]
   18: 0x3ad982 in -[UIViewController presentModalViewController:withTransition:]
   19: 0x3a6269 in -[UIViewController _tryRecursivelyPresentModalViewController:withTransition:]
   20: 0x3ad085 in -[UIViewController presentModalViewController:withTransition:]
   21: 0x4bc0 in -[RootViewController tableView:didSelectRowAtIndexPath:] at /Application/Classes/RootViewController.m:98
   22: 0x371794 in -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:]
   23: 0x367d50 in -[UITableView _userSelectRowAtPendingSelectionIndexPath:]
   24: 0x7a7f6 in __NSFireDelayedPerform
   25: 0x128afe3 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__
   26: 0x128c594 in __CFRunLoopDoTimer
   27: 0x11e8cc9 in __CFRunLoopRun
   28: 0x11e8240 in CFRunLoopRunSpecific
   29: 0x11e8161 in CFRunLoopRunInMode
   30: 0x1ae9268 in GSEventRunModal
   31: 0x1ae932d in GSEventRun
   32: 0x30a42e in UIApplicationMain
   33: 0x2914 in main at /Application/main.m:14
   34: 0x28a5 in start

Alloc: Block address: 0x04d90af0 length: 24
Stack - pthread: 0xa0078540 number of frames: 40
    0: 0x90e5a103 in malloc_zone_calloc
    1: 0x90e5a05a in calloc
    2: 0x13fdd0f in _internal_class_createInstanceFromZone
    3: 0x140087d in class_createInstance
    4: 0x123e687 in __CFAllocateObject2
    5: 0x12a2d64 in +[__NSArrayI __new::]
    6: 0x121faba in +[NSArray arrayWithObjects:count:]
    7: 0x127ca9 in -[NSSet(NSKeyValueSorting) sortedArrayUsingDescriptors:]
    8: 0x24b0d in -[Task getFullSession:intoArray:] at /Application/Task.m:177
    9: 0x604d in -[AViewController viewDidLoad] at /Application/Classes/AViewController.m:50
   10: 0x3a965e in -[UIViewController view]
   11: 0x3a7a57 in -[UIViewController contentScrollView]
   12: 0x3b8201 in -[UINavigationController _computeAndApplyScrollContentInsetDeltaForViewController:]
   13: 0x3b6831 in -[UINavigationController _layoutViewController:]
   14: 0x3b7b4c in -[UINavigationController _startTransition:fromViewController:toViewController:]
   15: 0x3b2606 in -[UINavigationController _startDeferredTransitionIfNeeded]
   16: 0x4cae01 in -[UILayoutContainerView layoutSubviews]
   17: 0x1e87451 in -[CALayer layoutSublayers]
   18: 0x1e8717c in CALayerLayoutIfNeeded
   19: 0x1e87088 in -[CALayer layoutIfNeeded]
   20: 0x3aab5f in -[UIViewController window:willAnimateRotationToInterfaceOrientation:duration:]
   21: 0x3238e9 in -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:]
   22: 0x5a2948 in -[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:]
   23: 0x3ad982 in -[UIViewController presentModalViewController:withTransition:]
   24: 0x3a6269 in -[UIViewController _tryRecursivelyPresentModalViewController:withTransition:]
   25: 0x3ad085 in -[UIViewController presentModalViewController:withTransition:]
   26: 0x4bc0 in -[RootViewController tableView:didSelectRowAtIndexPath:] at /Application/Classes/RootViewController.m:98
   27: 0x371794 in -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:]
   28: 0x367d50 in -[UITableView _userSelectRowAtPendingSelectionIndexPath:]
   29: 0x7a7f6 in __NSFireDelayedPerform
   30: 0x128afe3 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__
   31: 0x128c594 in __CFRunLoopDoTimer
   32: 0x11e8cc9 in __CFRunLoopRun
   33: 0x11e8240 in CFRunLoopRunSpecific
   34: 0x11e8161 in CFRunLoopRunInMode
   35: 0x1ae9268 in GSEventRunModal
   36: 0x1ae932d in GSEventRun
   37: 0x30a42e in UIApplicationMain
   38: 0x2914 in main at /Application/main.m:14
   39: 0x28a5 in start


The cause of this error is visible near the top of theblock: 
...
4: 0x127c89 in -[NSSet(NSKeyValueSorting) sortedArrayUsingDescriptors:]
5: 0x24b0d in -[Task getFullSession:intoArray:] at /Application/Task.m:177
...
2: 0x127c89 in -[NSSet(NSKeyValueSorting) sortedArrayUsingDescriptors:]
3: 0x24b0d in -[Task getFullSession:intoArray:] at /Application/Task.m:177
...
7: 0x127ca9 in -[NSSet(NSKeyValueSorting) sortedArrayUsingDescriptors:]
8: 0x24b0d in -[Task getFullSession:intoArray:] at /Application/Task.m:177
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值