如何在 Xcode 4 中设置 NSZombieEnabled?

发布于 2024-08-19 18:02:05 字数 87 浏览 3 评论 0原文

如何在 Xcode 4 中为可执行文件设置 NSZombieEnabledCFZombieLevel

How do I set up NSZombieEnabled and CFZombieLevel for my executable in Xcode 4?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

桃气十足 2024-08-26 18:02:05

在 Xcode 4.x 中,按

R

(或单击 Menubar > Product > 方案 > 编辑方案)

选择“诊断”选项卡并单击“启用僵尸对象”:

单击“启用僵尸对象”

这会将释放的对象转换为 NSZombie 实例,并在再次使用时打印控制台警告。这是一种调试辅助工具,可以增加内存使用(没有真正释放任何对象),但可以改进错误报告。

一种典型的情况是,当您过度释放一个对象并且您不知道是哪个对象时:

  • 有僵尸:-[UITableView release]:消息发送到已释放的实例
  • 没有僵尸:EXC_BAD_ACCESS

当您存档应用程序以提交 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":

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:

  • With zombies: -[UITableView release]: message sent to deallocated instance
  • Without zombies: EXC_BAD_ACCESS

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.

给不了的爱 2024-08-26 18:02:05

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...

初见终念 2024-08-26 18:02:05

我发现这个替代方案更方便:

  1. 单击“运行按钮下拉菜单”
  2. 从列表中选择配置文件
  3. 程序“Instruments”应该打开,您也可以在其中选择Zombies
  4. 现在您可以进行交互与您的应用程序一起尝试引发错误
  5. 一旦错误发生,您应该会得到有关对象何时被释放并因此被释放的提示。

Zombies

一旦检测到僵尸,您就会得到一个简洁的“僵尸堆栈”,显示有问题的对象何时出现分配以及保留或释放的位置:

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]

与使用 Xcode 方案的诊断选项卡相比的优点

  1. 如果您忘记取消选中诊断选项卡中的选项,则不会从内存中释放任何对象.

  2. 您将获得更详细的堆栈,其中显示您的损坏对象是通过哪些方法分配/释放或保留的。

    您将获得更详细的堆栈,其中显示您

I find this alternative more convenient:

  1. Click the "Run Button Dropdown"
  2. From the list choose Profile
  3. The program "Instruments" should open where you can also choose Zombies
  4. Now you can interact with your app and try to cause the error
  5. As soon as the error happens you should get a hint on when your object was released and therefore deallocated.

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:

  1. If you forget to uncheck the option in the diagnostic tab there no objects will be released from memory.

  2. You get a more detailed stack that shows you in what methods your corrupt object was allocated / released or retained.

鹤仙姿 2024-08-26 18:02:05

在 Xcode 4.2

  • 项目名称/编辑方案/诊断/
  • 启用僵尸对象复选框
  • 中,您已完成

In Xcode 4.2

  • Project Name/Edit Scheme/Diagnostics/
  • Enable Zombie Objects check box
  • You're done
战皆罪 2024-08-26 18:02:05

在 Xcode 7 中

<

或从 Product > 中选择 Edit Scheme 方案菜单

诊断选项卡中选择启用僵尸对象

xcode 7僵尸标志

作为替代方案,如果您更喜欢 .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 from Product > Scheme Menu

select Enable Zombie Objects form the Diagnostics tab

xcode 7 zombie flag

As 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/

衣神在巴黎 2024-08-26 18:02:05

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

甜味超标? 2024-08-26 18:02:05

在 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 !!!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文