I\'m developing an iPhone application. I have an EXC_BAD_ACCESS
that occurs only in the release target; when I build the debug target the exception does not occur.
Based on your gdb session, it seems possible that you're over-releasing some object, although I agree that the 0x3100000 seems improbable. Have you tried running Build and Analyze? Static analysis can catch many common over-release bugs.
Based on that memory address, a buffer overrun seems more likely. This could also explain why it only crashes in release mode when you're compiling with -O2 or greater. The optimizations may be laying out your memory in such a way that your buffer overrun happens to cause a crash in release mode but not in debug mode.
Are you doing anything funky with old school C void * pointers? Working with any null terminated C strings? Doing any pointer arithmetic?
In objc_msgSend
, r0
contains a pointer to the receiver of the message. Your app is crashing when it tries to load something pointed to by the receiver. The most likely explanation is that you are either messaging an object that hasn't been initialized, or an object that has already been freed, but there are other possibilities.
You also may want to have a look at "So you crashed in objc_msgSend"; it's written about the Intel OS X platform, but much of it also applies to the iPhone OS.
When u enable NSZombieEnabled you should check the console as it will probably tell u which line you're getting the EXC_BAD_ACCESS. From there you would be able to fix it. Don't forget to disable it for final release.