如何在 Xcode 4 中设置 NSZombieEnabled?
如何在 Xcode 4 中为可执行文件设置 NSZombieEnabled
和 CFZombieLevel
?
How do I set up NSZombieEnabled
and CFZombieLevel
for my executable in Xcode 4?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
在 Xcode 4.x 中,按
⌥⌘R
(或单击
Menubar
>Product
>方案
>编辑方案
)选择“诊断”选项卡并单击“启用僵尸对象”:
这会将释放的对象转换为 NSZombie 实例,并在再次使用时打印控制台警告。这是一种调试辅助工具,可以增加内存使用(没有真正释放任何对象),但可以改进错误报告。
一种典型的情况是,当您过度释放一个对象并且您不知道是哪个对象时:
-[UITableView release]:消息发送到已释放的实例
当您存档应用程序以提交 App Store 时,此 Xcode 设置将被忽略。在发布应用程序之前,您无需进行任何操作。
按⌥⌘R与选择产品>相同。按住 Alt 键运行。
单击“启用僵尸对象”复选框与在“参数”选项卡的“环境变量”部分中手动添加“NSZombieEnabled = YES”相同。
In Xcode 4.x press
⌥⌘R
(or click
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.
A typical case is when you over-release an object and you don't know which one:
-[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.
Pressing ⌥⌘R is the same as selecting Product > Run while keeping the Alt key pressed.
Clicking the "Enable Zombie Objects" checkbox is the same as manually adding "NSZombieEnabled = YES" in the section "Environment Variables" of the tab Arguments.
Jano 的答案是找到它的最简单方法。另一种方法是单击方案下拉栏 ->编辑方案->参数选项卡,然后在环境变量列中添加 NSZombieEnabled,在值列中添加 YES...
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...
我发现这个替代方案更方便:
配置文件
Zombies
一旦检测到僵尸,您就会得到一个简洁的“僵尸堆栈”,显示有问题的对象何时出现分配以及保留或释放的位置:
与使用 Xcode 方案的诊断选项卡相比的优点:
如果您忘记取消选中诊断选项卡中的选项,则不会从内存中释放任何对象.
您将获得更详细的堆栈,其中显示您的损坏对象是通过哪些方法分配/释放或保留的。
您将获得更详细的堆栈,其中显示您
I find this alternative more convenient:
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:
Advantages compared to using the diagnostic tab of the 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.
在 Xcode 4.2
In Xcode 4.2
在 Xcode 7 中
⌘<
或从
Product
> 中选择Edit Scheme
方案
菜单从
诊断
选项卡中选择启用僵尸对象
作为替代方案,如果您更喜欢
.xcconfig< /code> 文件,您可以阅读本文 https://therealbnut.wordpress.com/2012/01/01/setting-xcode-4-0-environment-variables-from-a-script/
On In Xcode 7
⌘<
or select
Edit Scheme
fromProduct
>Scheme
Menuselect
Enable Zombie Objects
form theDiagnostics
tabAs alternative, if you prefer
.xcconfig
files you can read this article https://therealbnut.wordpress.com/2012/01/01/setting-xcode-4-0-environment-variables-from-a-script/Cocoa 提供了一个很酷的功能,可以极大地增强您调试此类情况的能力。它是一个名为 NSZombieEnabled 的环境变量,观看这个视频,其中解释了如何设置 NSZombieEnabled目标C
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 video that explains setting up NSZombieEnabled in objective-C
在 Xcode 中 > 4.3:
您点击方案下拉栏->编辑方案->参数选项卡,然后在环境变量列中添加 NSZombieEnabled,并在值列中添加 YES。
祝你好运 !!!
In 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.
Good Luck !!!