Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 876
mrd Avatar asked Aug 05 '14 17:08

mrd


People also ask

What does Exc_bad_access mean Xcode?

What does EXC_BAD_ACCESS mean? EXC_BAD_ACCESS is an exception raised as a result of accessing bad memory. We're constantly working with pointers to memory in Swift that link to a specific memory address. An application will crash whenever we try to access a pointer that is invalid or no longer exists.

What does thread 1 Exc_bad_access mean?

EXC_BAD_ACCESS means that message was sent to a point in the memory where there's no instance of a class to execute it. Thus “bad access”. You will get EXC_BAD_ACCESS in 3 cases: An object is not initialized.

What is Exc_bad_access Kern_invalid_address?

Code Block. Exception Type: EXC_BAD_ACCESS (SIGSEGV) Exception Subtype: KERN_INVALID_ADDRESS at 0x0000000000000000. This indicates that your app crash because it tried to referenced NULL. Code Block.

What is zombie object in ios?

Once an Objective-C or Swift object no longer has any strong references to it, the object is deallocated. Attempting to further send messages to the object as if it were still a valid object is a “use after free” issue, with the deallocated object still receiving messages called a zombie object.


1 Answers

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.

like image 150
artud2000 Avatar answered Oct 10 '22 15:10

artud2000