Monday, October 26, 2009

Xcode: EXC_BAD_ACCESS

This Xcode console message is sometimes the only clue as to why an iPhone app just crashed:

Program received signal: “EXC_BAD_ACCESS”.


According to codza, this message indicates that a method on an object that no longer exists has been called. In my limited experience, it means my code has released something it didn't own. For example, I was recently getting this crash because I was releasing a UIImage property in the dealloc method but not taking ownership of the value back when I was setting the property.

The best advice I've seen for debugging this problem involves putting the executable in a mode that keeps around "zombie" copies of deallocated objects, thus allowing the debugger to display more information about what wrong. And it's easy to configure. Truly a huge time saver.

No comments: