Sunday, February 13, 2011

How to resolve EXC_BAD_ACCESS

Normally EXC_BAD_ACCESS error refers to an error where a message was sent to an object that was already released.  This usually happens when a methods or object releases an object that is not theirs to release.

The stack trace is usually gone by the time the error is caught and so it is very hard to debug.  Until now that is.  You can set a NSZombieEnabled environment variable in xcode so that the Objective C runtime will leave an object behind every time an object is deallocated.  Once a message is sent to this object, a message is displayed and execution stops.

To set this variable, go to the info panel of the executable in xcode, and create a newenvironment variable in the arguments tab by clicking the plus sign in the lower left corner of the window. Name the variable NSZombieEnabled, type YES for the value and make sure that the checkbox is selected.

All this great information was learned on this blog:
http://www.codza.com/how-to-debug-exc_bad_access-on-iphone

No comments:

Post a Comment