EXC_BAD_ACCESS with [CALayer retainCount]

12 Mar 2012

Normally, it means that you release an auto-released 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 auto-released 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!

Give it a kudos