objective-c 如何在 Xcode 4 中设置 NSZombieEnabled?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2190227/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I set up NSZombieEnabled in Xcode 4?
提问by Chetan
How do I set up NSZombieEnabledand CFZombieLevelfor my executable in Xcode 4?
如何设置NSZombieEnabled和CFZombieLevel我的可执行文件在Xcode 4?
回答by Jano
In Xcode 4.x press
在 Xcode 4.x 中按
??R
??R
(or click Menubar> Product> Scheme> Edit Scheme)
(或点击Menubar> Product> Scheme> Edit Scheme)
select the "Diagnostics" tab and click "Enable Zombie Objects":
选择“诊断”选项卡并单击“启用僵尸对象”:


This turns released objects into NSZombie instances that print console warnings when used again. This is a debugging aid that increases memory use (no object is really released) but improves error reporting.
这会将释放的对象转换为 NSZombie 实例,再次使用时会打印控制台警告。这是一个调试辅助工具,它增加了内存使用(没有真正释放对象)但改进了错误报告。
A typical case is when you over-release an object and you don't know which one:
一个典型的情况是当你过度释放一个对象而你不知道是哪一个时:
- With zombies:
-[UITableView release]: message sent to deallocated instance - Without zombies:

- 与僵尸:
-[UITableView release]: message sent to deallocated instance - 没有僵尸:

This Xcode setting is ignored when you archive the application for App Store submission. You don't need to touch anything before releasing your application.
当您为 App Store 提交归档应用程序时,将忽略此 Xcode 设置。在发布您的应用程序之前,您不需要接触任何东西。
Pressing ??Ris the same as selecting Product > Run while keeping the Altkey pressed.
Clicking the "Enable Zombie Objects" checkbox is the same as manually adding "NSZombieEnabled = YES" in the section "Environment Variables" of the tab Arguments.
按下??R与在按住键的同时选择产品 > 运行相同Alt。
单击“启用僵尸对象”复选框与在选项卡参数的“环境变量”部分中手动添加“NSZombieEnabled = YES”相同。
回答by learner2010
Jano's answer is the easiest way to find it.. another way would be if you click on the scheme drop down bar -> edit scheme -> arguments tab and then add NSZombieEnabled in the Environment Variables column and YES in the value column...
Jano 的答案是找到它的最简单方法.. 另一种方法是,如果您单击方案下拉栏 -> 编辑方案 -> 参数选项卡,然后在环境变量列中添加 NSZombieEnabled 并在值列中添加 YES...
回答by Besi
I find this alternative more convenient:
我发现这个替代方案更方便:
- Click the "Run Button Dropdown"
- From the list choose
Profile - The program "Instruments" should open where you can also choose
Zombies - Now you can interact with your app and try to cause the error
- As soon as the error happens you should get a hint on when your object was released and therefore deallocated.
- 单击“运行按钮下拉菜单”
- 从列表中选择
Profile - 程序“仪器”应该打开,您也可以选择
Zombies - 现在您可以与您的应用程序交互并尝试导致错误
- 一旦发生错误,您应该得到有关何时释放对象并因此解除分配的提示。


As soon as a zombie is detected you then get a neat "Zombie Stack" that shows you when the object in question was allocated and where it was retained or released:
一旦检测到僵尸,您就会得到一个整洁的“僵尸堆栈”,显示相关对象的分配时间以及保留或释放的位置:
Event Type RefCt Responsible Caller
Malloc 1 -[MyViewController loadData:]
Retain 2 -[MyDataManager initWithBaseURL:]
Release 1 -[MyDataManager initWithBaseURL:]
Release 0 -[MyViewController loadData:]
Zombie -1 -[MyService prepareURLReuqest]
Advantages compared to using the diagnostic tab of the Xcode Schemes:
与使用 Xcode Schemes 的诊断选项卡相比的优势:
If you forget to uncheck the option in the diagnostic tab there no objects will be released from memory.
You get a more detailed stack that shows you in what methods your corrupt object was allocated / released or retained.
如果您忘记取消选中诊断选项卡中的选项,则不会从内存中释放任何对象。
你会得到一个更详细的堆栈,显示你损坏的对象被分配/释放或保留的方法。
回答by pratap shaik
In Xcode 4.2
在 Xcode 4.2 中
- Project Name/Edit Scheme/Diagnostics/
- Enable Zombie Objects check box
- You're done
- 项目名称/编辑方案/诊断/
- 启用僵尸对象复选框
- 你完成了
回答by IgnazioC
On In Xcode 7
在 Xcode 7 中
?<
?<
or select Edit Schemefrom Product> SchemeMenu
或Edit Scheme从Product>Scheme菜单中选择
select Enable Zombie Objectsform the Diagnosticstab
选择Enable Zombie Objects表格Diagnostics选项卡
As alternative, if you prefer .xcconfigfiles you can read this article https://therealbnut.wordpress.com/2012/01/01/setting-xcode-4-0-environment-variables-from-a-script/
作为替代方案,如果您更喜欢.xcconfig文件,您可以阅读这篇文章https://therealbnut.wordpress.com/2012/01/01/setting-xcode-4-0-environment-variables-from-a-script/
回答by user2554822
Cocoa offers a cool feature which greatly enhances your capabilities to debug such situations. It is an environment variable which is called NSZombieEnabled, watch this videothat explains setting up NSZombieEnabled in objective-C
Cocoa 提供了一个很酷的功能,可以极大地增强您调试此类情况的能力。它是一个名为 NSZombieEnabled 的环境变量,观看这个 解释在 Objective-C 中设置 NSZombieEnabled 的视频
回答by Dipak Narigara
In Xcode > 4.3:
在 Xcode > 4.3 中:
You click on the scheme drop down bar -> edit scheme -> arguments tab and then add NSZombieEnabled in the Environment Variables column and YES in the value column.
单击方案下拉栏 -> 编辑方案 -> 参数选项卡,然后在环境变量列中添加 NSZombieEnabled,在值列中添加 YES。
Good Luck !!!
祝你好运 !!!

