2010-02-03 07:01 阅读 227

如何在 Xcode 4中设置启用了 nszombiate?

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


  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

7条回答 默认 最新

  • 已采纳
    csdnceshi61 derek5. 2011-02-07 01:55

    In Xcode 4.x press


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

    点赞 26 评论 复制链接分享
  • csdnceshi60 ℡Wang Yan 2012-04-11 07:18

    In Xcode 4.2

    • Project Name/Edit Scheme/Diagnostics/
    • Enable Zombie Objects check box
    • You're done
    点赞 9 评论 复制链接分享
  • csdnceshi79 python小菜 2012-01-14 15:10

    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.


    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.

    点赞 5 评论 复制链接分享
  • csdnceshi69 YaoRaoLov 2013-10-22 04:41

    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

    点赞 5 评论 复制链接分享
  • csdnceshi74 7*4 2011-03-16 14:22

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

    点赞 2 评论 复制链接分享
  • weixin_41568131 10.24 2015-08-20 06:50

    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/

    点赞 2 评论 复制链接分享
  • weixin_41568134 MAO-EYE 2013-07-05 06:38

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

    点赞 评论 复制链接分享