NSZombie and XCode Oh My!

Matthew Campbell, February 6th

Today I was reading my second favorite iPhone programming website, iPhoneKicks.com, when I can across this article:

http://www.mobileorchard.com/14-essential-xcode-tips-tricks-and-resources-for-iphone-devs/

You can find some of these tricks helpful as you start to get more familiar with XCode.  In particular, I saw in the comments a mention of NSZombieEnabled.  Cool name right?

It is way more than that – if you have encountered memory problems (aka – your app crashes for no apparent reason because you attempted to use an object that you deallocated to soon) setting NSZombieEnabled = YES can help you diagnose the problem.

Normally, when your app crashes in this way and you look at the log it tells you nothing (thanks Apple!).  However, if you select your executable (under Executables in Xcode), hit the info button (round blue thing at the top), select arguments and put this in the bottom screen NSZombieEnabled = YES the log will give you more information.

Now, if your app crashes the log will have an indication of the object you attempted to access that has already been deallocated.  Not forget to turn it off before you deploy it – you don’t want a bunch of nszombies running around your clients phones…