Chasing Zombies in XCode 4

How to enable your XCode project with Zombie tracing — a quickie

Ok, this will be a short one. Probably I will create a category like “code snippets and hints” to include all these small articles. This is about zombies in your coding projects and how to chase them.

Enabling a project to trace zombies is different in XCode 4 than in previous versions. There is a special section inside “Run for debug” scheme.

Chasing zombies via edit scheme

Edit scheme in project options.

You have at least three ways to access this. One is using the “edit scheme” option in the drop down. The second is to choose product -> scheme -> edit scheme from XCode menu.

Chasing zombies in XCode 4 - edit scheme from menu

Choosing edit scheme from menu.

The third is to access edit scheme panel by pressing Cmd + Shift + <. The fourth is to access run options by pressing Cmd + Opt + R. In all cases, a dialog will open:

Run panel with enable zombie objects option under memory management section.

Run panel with enable zombie objects option under memory management section.

Check “Enable Zombie Objects” under “Memory Management” section and click Done. Test it by sending a message to a deallocated instance. Add, for example, this code in the awakeFromNib method:

    aString = [[NSString alloc] initWithFormat:@"Test"];
    [aString release];
    NSLog(@"%@", aString);

When the app starts, the following will appear on the console (and the app will crash):

A zombie: message to a deallocated instance — captured at runtime.

A zombie: message to a deallocated instance — captured at runtime.

Use it wisely. 😉

Leave a Reply

Your email address will not be published. Required fields are marked *