Thursday, June 9, 2011

"EXC _BAD_ACCESS" error handling


All of us are well aware of this error .Most of us know the solution also for this, that is "Using Zombies".You get your problem fixed also using it. There are few scenarios when you get the kind of object was released but we dont get the exact line number where the problem is even after spending long time on debugging.Such a problem happened with me also & found a short simple solution for it.My this blog will through light on using zombies in your project & also how you can get the exact line number.I am sure it will be helpful for you all.

Introduction



This kind of problem is usually the result of over-releasing an object. It can be very confusing, since the failure tends to occur well after the mistake is made. The crash can also occur while the program is deep in framework code, often with none of your own code visible in the stack.

Enabling Zombies


Steps

1. Select Groups & Files > Executables

Click for full-size image
2. Select your project within Executables & press info button , following screen pops up


Click for full-size image
3. Select Arguments from top segmented control


Click for full-size image


4. Now select the botton "+" button

Click for full-size image

& add the following key value pairs
NSZombieEnabled = YES
CFZombie = 5
MallocStackLoggingNoCompact = 1

Click for full-size image


Debugging "EXC_BAD_ACESS" error


After enabling zombie & running the project you get something like


(gdb) continue
2011-06-09 11:46:08.404 test [6842:40b] *** -[_NSArrayI release]:message sent to deallocated instance 0X64a4900

in your console
Then add

(gdb) info malloc-history 0x64a4900
it will show the lines that was creating the error

No comments:

Post a Comment