When an object crashes you can use Xcode to replace this object with an NSZombie. This way you can find out more information about the crashed object. Here’s how:
1. Edit the Run scheme (click on your Project name to the right of the Run / Stop buttons (top left of Xcode) and choose Edit Scheme)
2. Arguments > Environment Variables > NSZombieEnabled > YES
3. Diagnostics > Enable Zombie Objects
Then run via Instruments (Xcode > Product > Profile (Cmd I)) and select Zombies.
Pause Instruments when your app loads, click the i in Allocations and make sure “Record reference counts” and “Enable NSZombie detection” are enabled.
Click Record again and trigger your crash.
You’ll get a Zombie Messaged dialog at the crash.
http://www.snowcrash.eu/wp-content/uploads/2013/04/Screen-Shot-2013-04-13-at-13-Apr-16.23.21.png 304w" sizes="(max-width: 300px) 100vw, 300px" />
Click the arrow to see a full stack trace.
To work out the cause of the crash switch on the Extended Detail side pane (View > Extended Detail (or Cmd E)). This opens up a pane which has a section titled Stack Trace. Note that lines in bold are your code. Double click on one of these lines to open up the code.
To return to the stack trace, click History to the right of Statistics the lower middle pane.
http://www.snowcrash.eu/wp-content/uploads/2013/04/Screen-Shot-2013-04-13-at-13-Apr-16.57.46.png 436w" sizes="(max-width: 300px) 100vw, 300px" />
If you look at the first line you’ll see what the object was. It’ll say the Address, the Category and the Event Type (i.e. the object name and Malloc).
Further Retain / Release / Autorelease events are listed in subsequent chronological order.
More on using Instruments here:
and much more here:
And a bit more here on zombies
See this very useful hack on how to run app in Instruments with Allocations instrument and get both zombie detection and allocation tracking: http://stackoverflow.com/questions/6797944/how-do-you-enable-nszombie-in-instruments-of-xcode-4-1-under-lion