More about zombies and XCode


Some time ago I did a very short introduction about enabling zombies when debugging in XCode. As a refresher, zombies is a Cocoa feature that turns any object going to be deallocated into a NSZombie instance. This will not prevent your application from crashing, but instead of getting a stack dump from Xcode that is a pain to read and understand, you get something more human–readable.

Working on a kernel extension for my Agilent DSO-X 2002A scope (see here), I frequently got EXC_BAD_ACCESS. One thing that nags me about these is that they are extremely difficult to debug

A pointer to an object is never set to nil when the object is released. The pointer continues to point to the same memory location that it always did. That doesn’t mean that whatever is now at that location is a valid object, however. For that reason, you should never use a pointer after you’ve released the object it points to. If you’re going to continue to use that pointer, you should change its value so that it’s either nil or points to some other (valid) object.

NSZombieEnabled is just a debugging tool that helps you find places in your code where you’re accessing invalid objects. If you’ve found a place where you’re doing that, you’ve found a bug in your code and you need to fix it, not tolerate it.

If the environment variable NSZombieEnabled is set to true, the compiler is directed to substitute an object of type NSZombie for any objects that are released to a reference count of zero. As a consequence, no more of those objects should exist. If a message is then sent to one of these deallocated objects (which are now NSZombie objects), the zombie is flagged, the app crashes, recording stops, and a Zombie Messaged dialog appears. You can then examine the retain and release history of the zombie object to determine exactly where the problem occurred.

Cool stuff. See more here.

Things to do, drafts and timeline

Today, while I went over all my posts, I noticed that I have a large list of 43 draft posts. These are articles that I started writing, thought to be interesting, but I had limited bandwidth to finish. I need some planning with these, thus I put them down, maybe getting some input from you […]

Some thoughts on the Responder Chain

I had a lot to do these days and did not manage to keep up with the blog. Very busy time at the office before Christmas. Luckily, I’ll get my vacation soon by I swear I will not spend it on much anything else than reading paper books. And books which are not about programming, […]

Leave a Reply

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