365Cocoa

A snippet of Objective-C code per day, 365 days long.
Written by Pieter Omvlee, developer and owner of Bohemian Coding.

Mar 19

Day 21: Lazy: NSZombieEnabled

I feel lazy today, so I’m going for a quick one; NSZombieEnabled. This environmental variable can be your saviour in times of memory issues. Whenever NSZombieEnabled is set, instead of just deallocating objects, they will be replaced by NSZombie objects which throw an exception whenever they are accessed, giving you nice stack trace as an alternative to an otherwise non-descriptive EX_BAD_ACCESS for example.

Enable it by going to your executable, double-click and then add NSZombieEnabled with a value of YES to the environment variables. Don’t forget to remove this again when you no longer need it or you might accidentally keep it there in the finished product, making sure your app will consume an unnecessarily huge amount of memory.


  1. 365cocoa posted this