Skip to main content

Using NSZombie with Instruments

·1 min

Cocoa’s NSZombie class helps you discover where you are accessing a deallocated object in your code. For those of you running Snow Leopard, Instruments has support for NSZombie so you can use NSZombie without having to make any changes to your Xcode project.

Checking for zombies is pretty simple. Open your project in Xcode. Choose Run > Run With Performance Tool > Zombies. Your application will launch and Instruments will trace its execution. If your application accesses a deallocated object, a zombie message appears in Instruments.

Instruments Zombie Message.png

Clicking the focus button next to the memory address shows the history of that memory address. The Responsible Caller column tells you where you’re trying to access a deallocated object.

If the Run With Performance Tool option is grayed out in Xcode, launch Instruments (or choose File > New if Instruments is already running) and select the Zombies template. The Zombies template is available for Mac applications and iPhone applications running in the Simulator. Use the Target menu in the trace document window toolbar to choose your application. Click the Record button to start recording.