Zombies & Coders

Anurag Pandit
MindOrks
Published in
3 min readJul 12, 2018

Codes are neither good nor bad. Like a fire they can either keep you warm or burn you to death, depending on how they’re used.

Zombies !!!
Yes! Who said zombies aren’t real, If you’re an iOS developer you would be quite aware of them. No? Don’t worry let’s explore a bit.

At some point of time, we unknowingly or knowingly implants them in our code and the worse happens when we’d to kill them.
Zombies are nothing but the objects which are half dead, or half released or retained. Well in this article we’ll not only going to just trace them down but also do it in a more simplified way.

Have you ever faced trouble in tracking a deallocated object?
Have you ever faced a crash which read as “message sent to deallocated instance” ?
True!!! Then this article is for you, let’s begin .

At times, the binary language gives us a hard hit. Can you guess the class name from this “0x10010d681” ? Perhaps not. Assume this is a deallocated object, now difficulty level raised even harder. Though Xcode provide us a great tool to understand as well as trace them through “Instruments”. Instruments is a great tool where we’ve tons of profiling templates; from “Allocations” to “Leaks” to “Zombies”. But today we won’t explore Instrument rather will go by a more plainer way to track down the memory history of the zombie object.

To know is always better, no matter what the answer might be

So first we will go to edit the schemes of the project:

Here, under Diagnostics, we’ve various Memory Management options.
Select “Zombie objects” and then for Logging select “Malloc Stack”. That’s it we’re ready to run the project.

Now, when we’ll come across a crash which could be caused by a zombie instance, This is how we are going to debug it down by entering the following commands in xcode’s console:

a) (lldb) command script import lldb.macosx.heap
This produces a result which will be similar to this:

Result produced by above command if the script is successfully executed

b) (lldb) malloc_info — type 0x10010d681

Only through these two commands, We’ll get the complete memory stack trace for “0x10010d681”. We can now see the exact line & class of the zombie instance and knock it down.

Kill the Zombie

Aforementioned commands are helpful for getting the information about a specific heap allocation. With the help of these two we can cast the result to any dynamic type that can be deduced.

That’s all folks! Hope you’ve found this article interesting. Happy coding. :)

--

--