Mar 12, 2012

EXC_BAD_ACCESS with [CALayer retainCount]

EXC_BAD_ACCESS might mean many things.

Normally, it means that you release an autorelease object, release too many times, or use a released object.

Here is the way to debug it.

First of all, you need to turn on NSZombieEnabled. To turn it on:

1. you need to go to "Project -> Set Active Executable (...)"
2. Under the tab "Arguments" and in the box "Variables to be set in the environment", Add a new variable named "NSZombieEnabled" with the value "YES"

Now when you get an EXC_BAD_ACCESS, it will tell you what happens.

One of the scenarios is that you will get [CALayer retainCount].

This means that you release an autoreleased view or a view too many times.

Now you can go find out....

I took like 2 hours to find out that I release a view too many times....

Good luck!