如何在 Xcode 中启用 NSZombie?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5386160/
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 to enable NSZombie in Xcode?
提问by jason
I have an app that is crashing with no error tracing. I can see part of what is going on if I debug, but can't figure out which object is "zombie-ing".
我有一个应用程序崩溃,没有错误跟踪。如果我调试,我可以看到部分正在发生的事情,但无法弄清楚哪个对象是“僵尸”。
Does anybody know how to enable NSZombie in Xcode 4?
有人知道如何在 Xcode 4 中启用 NSZombie 吗?
回答by u596219
Environment variables are now part of the "scheme".
环境变量现在是“方案”的一部分。
To edit the scheme and turn on zombies:
要编辑方案并打开僵尸:
In the "Product" menu, select "Edit Scheme".
Go to the "Run Foo.app" stage in the left panel, and the "Arguments" tab on the right.
Add
NSZombieEnabled
to the "Environment Variables" section and set the value toYES
, as you could in Xcode 3.
在“产品”菜单中,选择“编辑方案”。
转到左侧面板中的“Run Foo.app”阶段,以及右侧的“Arguments”选项卡。
添加
NSZombieEnabled
到“环境变量”部分并将值设置为YES
,就像在 Xcode 3 中一样。
In Xcode 4.1 and above, there's also a checkbox on the "Diagnostics" tab of the "Run" stage to "Enable Zombie Objects".
在 Xcode 4.1 及更高版本中,“运行”阶段的“诊断”选项卡上还有一个复选框以“启用僵尸对象”。
With Xcode 6.4:
使用 Xcode 6.4:
回答by Moshe Kravchik
I encountered the same problem with troubleshooting EXC_BAD_ACCESS and had hard time to find the setting with Xcode 4.2 (the latest one that comes with iOS5 SDK). Apple keeps on moving things and the settings are no longer where they used to be.
我在排除 EXC_BAD_ACCESS 故障时遇到了同样的问题,并且很难找到 Xcode 4.2(iOS5 SDK 附带的最新版本)的设置。Apple 不断改进,设置不再像以前那样。
Fortunately, I've found it and it works for the device, not just Simulator. You need to open the Product menu in the Xcode, select Edit scheme and then choose the Diagnostics tab. There you have "Enable Zombie Objects". Once selected and run in debugger will point you to the double released object! Enjoy!
幸运的是,我找到了它并且它适用于设备,而不仅仅是模拟器。您需要在 Xcode 中打开产品菜单,选择编辑方案,然后选择诊断选项卡。在那里你有“启用僵尸对象”。选择并在调试器中运行后,您将指向双重发布的对象!享受!
In short
简而言之
Product->Edit Scheme->Diagnostics-> Click Enable Zombie Objects
回答by Shane Fitzgibbon
Product > Profile will launch Instruments and then you there should be a "Trace Template" named "Zombies". However this trace template is only available if the current build destination is the simulator - it will not be available if you have the destination set to your iOS device.
Product > Profile 将启动 Instruments,然后你应该有一个名为“Zombies”的“Trace Template”。但是,此跟踪模板仅在当前构建目标是模拟器时可用 - 如果您将目标设置为 iOS 设备,它将不可用。
Also another thing to note is that there is no actual Zombies instrument in the instrument library. The zombies trace template actually consists of the Allocations instrument with the "Enable NSZombie detection" launch configuration set.
另外要注意的另一件事是乐器库中没有实际的 Zombies 乐器。僵尸跟踪模板实际上由具有“启用 NSZombie 检测”启动配置集的分配工具组成。
回答by Dave DeLong
It's a simple matter of setting an environment variable on your executable (NSZombieEnabled = YES)
, and then running/debugging your app as normal.If you message a zombie, your app will crash/break to debugger and NSLog
a message for you.
在您的可执行文件上设置环境变量(NSZombieEnabled = YES)
,然后正常运行/调试您的应用程序是一件简单的事情。如果您向僵尸发送消息,您的应用程序将崩溃/中断到调试器并NSLog
为您发送一条消息。
For more information, check out this CocoaDev page: http://www.cocoadev.com/index.pl?NSZombieEnabled
有关更多信息,请查看此 CocoaDev 页面:http: //www.cocoadev.com/index.pl?NSZombieEnabled
Also, this process will become much easier with the release of 10.6 and the next versions of Xcode and Instruments. Just saying'. =)
此外,随着 10.6 和下一个版本的 Xcode 和 Instruments 的发布,这个过程将变得更加容易。就是说'。=)
回答by garageàtrois
Product > Profile will pop up Instruments. Select zombies from the panel and go nuts.
Product > Profile 会弹出Instruments。从面板中选择僵尸然后发疯。
回答by PJR
Go to Product - Scheme - edit scheme - Arguments - Environment Variablesset NSZombieEnabled = YES
转到产品-方案-编辑方案-参数-环境变量设置NSZombieEnabled = YES
回答by Dax
In xcode 4.2
在 xcode 4.2 中
Goto, Product -> edit scheme -> click Run yourappname.app -> Diagonostics -> Enable Zombie object.
转到,产品 -> 编辑方案 -> 单击运行 yourappname.app -> Diagonostics -> 启用 Zombie 对象。
回答by Mark Johnson
Here's a video and explaination how to use Instruments and NSZombie to find and fix memory crashes on iOS: http://www.markj.net/iphone-memory-debug-nszombie/
这是如何使用 Instruments 和 NSZombie 在 iOS 上查找和修复内存崩溃的视频和说明:http: //www.markj.net/iphone-memory-debug-nszombie/
回答by Dov
As of Xcode 3.2.5 and Snow Leopard (Mac OS X 10.6), you can run your code through the Zombies instrument: Run > Run with Performance Tool > Zombies
. That allows you to see particular objects and their retain counts on a timeline.
从 Xcode 3.2.5 和 Snow Leopard (Mac OS X 10.6) 开始,您可以通过 Zombies 工具运行您的代码:Run > Run with Performance Tool > Zombies
. 这使您可以在时间轴上查看特定对象及其保留计数。
回答by Gani414
In Xcode 4.5.2 goto Product -> Edit Scheme -> and Under the Diagnostics tab check the check box in between Objective C and Enable Zombie Objects and Click on OK
在 Xcode 4.5.2 中,转到 Product -> Edit Scheme -> 并在 Diagnostics 选项卡下选中 Objective C 和 Enable Zombie Objects 之间的复选框,然后单击 OK