~If you would like to request a tutorial, email Collateral at collateraldamag3@gmail.com~

Share This!

iPhone Tutorial ~ NSZombieEnabled and EXC_BAD_ACCESS


 EXC_BAD_ACCESS is an error received when a command is given to an deallocated target. Basically, you've released the object that your trying to send commands.  The only problem is, the error isn't very descriptive in telling you which object gave you that error, making it tricky to fix. 

Well there is a feature that a lot of people don't know about called "NSZombieEnabled". This makes it A LOT easier to find and debug Bad-Access errors. How it works is by leaving a dummy or "zombie" of every object you release in memory and then alerts you when you have sent a command to one of the dummies. Here is a picture of "NSZombieEnabled" in action:

It shows the exact same scenario as the top picture, except with "NSZombieEnabled" enabled. 
So how do we set this up? Its actually VERY simple. First right-click on your executable, and click "Get Info"

Then go to the "Arguments" tab and click on the bottommost plus sign (environmental variables). Then fill in the information as follows (REMEMBER TO CLICK THE CHECKBOX):

Then build and debug your program. It should now tell you the deallocated object that you sent a command to.
Just remember to uncheck the box when your ready to release. 

No comments:

Post a Comment

This entry is filed under .

You can also follow any responses to all entry through the RSS Comments feed.