For any EXC_BAD_ACCESS errors, you usually try to send a message to the issued object. The BEST way to track these actions is used by NSZombieEnabled .
This works by never releasing any object, but completing it as a โzombieโ and setting a flag inside it that says it would normally be released. Thus, if you try to access it again, he still knows what it was before you made a mistake, and with this little information you can usually backtrack to find out what the problem is.
This is especially helpful in background threads when the debugger sometimes tricks into any useful information.
IT IS VERY IMPORTANT TO NOTE , however, you need to be 100% sure that this is only in your debugging code and not in your distribution code. Since nothing is ever released, your application will flow, flow and flow. To remind me to do this, I injected this log into my appdelegate:
if(getenv("NSZombieEnabled") || getenv("NSAutoreleaseFreedObjectCheckEnabled")) NSLog(@"NSZombieEnabled/NSAutoreleaseFreedObjectCheckEnabled enabled!");
If you need help finding the exact string, do Build-and-Debug ( CMD-Y ) instead of Build-and-Run ( CMD-R ). When the application crashes, the debugger will show you which line, and in combination with NSZombieEnabled, you should know exactly why.
coneybeare Oct 25 '09 at 21:15 2009-10-25 21:15
source share