iOS engineer who likes clean, simple designs and sans-serif.

Loading

Message sent to deallocated instance (Swift)

(Written as of XCode 6.1.1, iOS8)
Man, these cryptic Swift errors can be frustrating! This week, I kept getting this deallocation error and could not figure out what was going on.

*** -[Not A Type release]: message sent to deallocated instance 0x7fb682f0

What the heck does that even mean!?! How about a line number please? An object or class name maybe? What is “Not A Type”? ARRRRRG. I wanted to pull my hair out.

After a while, I did figure out a slicker way to debug this issue. Maybe it will save you some time and frustration.

Step 1: Find the memory address

Let’s think about this. We have the object’s memory address. In my case, it is:

0x7fb682f0

Okay, well if I could somehow figure out what type of object this is, that would help me debug the issue. I’m suspicious that it’s some kind of C code (and not Objective C or Swift code), but that actually doesn’t help me as there is a lot of image manipulation and animation going on in this controller.

Step 2: Open Allocations Instrument

Okay, well debugger and console are pretty unhelpful as I don’t even know where the problem is. I guess I could set up breakpoints everywhere… but that’s pretty inefficient as well.

Instead, I decided to pop open Instruments and see if I learn how to use Allocations to figure this out.
To get here, I went to the XCode menu => Open Developer Tool => Instruments. Then choose “Allocations”.

messageSentToDeallocatedInstance3

Step 3: Enable NSZombie Detection and Record

Click on Allocations and check “Enable NSZombie Detection” under “Launch Configuration for Heap Allocations”.

messageSentToDeallocatedInstance4

Restart the app on your simulator or device and on the top menu bar, select your simulator and then the current app. Note that every time you restart the app, you’ll need to re-select your app here.

messageSentToDeallocatedInstance1

Step 4: Replicate the Issue

Okay, so now redo the steps you did before to replicate the issue and cause the crash. This time, however,
you will a “Zombie Messaged” prompt, with a much better description of the object.

messageSentToDeallocatedInstance2

Step 5: Fix the Issue

Give this info, you should now be able to find the problem and fix it!

Happy Swifting!

Leave a Comment