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.
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.
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:
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):
Use it wisely. 😉