Search code examples
iosdebuggingexc-bad-access

iOS EXC_BAD_ACCESS: How to debug?


I am getting an EXC_BAD_ACCESS. I know what this usually means: Trying to access an object that doesn't exist (anymore) is the most likely cause.

So, where do I find that?

I have read numerous posts on the internet, and they all say:

"Enable NSZombie" in the scheme.

Now when I run the debugger, for what should I look? I can not see any difference...

Note: This is not about a perticular error in my code, but generally how to use the debugger with NSZombie enabled


Solution

  • What I would do it will be to locate a breakpoint just one line above the green arrow showing the EXC_BAD_ACCESS error. Then run again your code and reproduce the steps to generate the crash.

    When you get to your breakpoint you can check that your objects are valid objects using right click and print description in the left side of your console within Xcode or typing the command 'po' within the console section in XCode. That's how I usually detect the errors.

    Something useful is to trace the stack once the debugger stopped. It show in the left panel the threads and chain of invocations of the methods before the break point.

    Hope this helps and hope my description of the alternative in how to track the error helps.