Zombies & Coders

Anurag Pandit
Jul 12, 2018 · 3 min read

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. :)

MindOrks

Our community publishes stories worth reading on Android Development

Anurag Pandit

Written by

I click | I dream | I write | I code

MindOrks

MindOrks

Our community publishes stories worth reading on Android Development

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade