Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable and Debug Zombie objects in iOS using Xcode 5.1.1

I have an iOS(7.1) app which crashes due to EXC_BAD_ACCESS. If I am not wrong, this happens due to the use of an object which is already de-allocated. After a bit of searching, I found out that enabling Zombie objects help to pin point the line of error. As I am using xcode 5.1.1, I have done the following to Enable Zombie Objects.

Product -> Scheme -> Edit Scheme


And then, checking the Enable Zombie Objects checkbox,

Checking <code>Enable Zombie Objects</code>


Then I went to Instruments panel, selected Zombies,clicked Profile and got this,

iOS simulator and Instruments panel


Now the simulator (in the left background), which had a button and a textfield is running blank and also I can't understand anything on the Instruments panel.

What should be the next step? I mean how can I get the lines which are causing the bad access? I am stuck on this for hours but still couldn't find the procedure.

Any help is appreciated.

like image 853
Sibir Avatar asked Sep 23 '14 11:09

Sibir


People also ask

How do you use zombie objects in Xcode?

The following approach applies to Xcode 6 and 7. Click the active scheme in the top left and choose Edit Scheme. Select Run on the left and open the Diagnostics tab at the top. To enable zombie objects, tick the checkbox labeled Enable Zombie Objects.

How do you enable objects in zombies?

You need to open the Product menu in the Xcode, select Edit scheme and then choose the Diagnostics tab. There you have "Enable Zombie Objects". Once selected and run in debugger will point you to the double released object! Enjoy!

What are zombie objects?

Zombie objects are a debugging feature of Cocoa / CoreFoundation to help you catch memory errors - normally when an object's refcount drops to zero it's freed immediately, but that makes debugging difficult.

What is NSZombie?

It's a memory debugging aid. Specifically, when you set NSZombieEnabled then whenever an object reaches retain count 0, rather than being deallocated it morphs itself into an NSZombie instance. Whenever such a zombie receives a message, it logs a warning rather than crashing or behaving in an unpredictable way.


1 Answers

Accessing a deallocated object is not the only reason you would get EXC_BAD_ACCESS. Other causes of bad access errors include accessing nil pointers and going past the bounds of an array.

Looking at your screenshots, you are not using a deallocated object. If you were using a deallocated object, the Zombies template in Instruments would let you know. Instruments would show a message similar to the following:

enter image description here

Your next step should be to set an exception breakpoint in Xcode. When your app crashes, Xcode will pause your app at the point where the crash occurs. To set an exception breakpoint, open the breakpoint navigator by choosing View > Navigators > Show Breakpoint Navigator. Click the + button at the bottom of the navigator and choose Add Exception Breakpoint.

like image 128
Swift Dev Journal Avatar answered Oct 17 '22 16:10

Swift Dev Journal