How do I set up NSZombieEnabled in Xcode 4?

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


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:

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

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


    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.
  • 植物大战僵尸

    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 :

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

  • 链接地址: http://www.djcxy.com/p/35372.html

    上一篇: “档案”是灰色的?

    下一篇: 我如何在Xcode 4中设置NSZombieEnabled?