How To Debug Memory Leaks with XCode and Instruments Tutorial
Here’s the advice I generally give to developers when you hit an EXC_BAD_ACCESS error:
- Set the NSZombieEnabled argument in your executable options, which sometimes helps narrow down the cause
- Run with Apple Instruments such as Leaks to look for memory issues
- Set a breakpoint in your code and step through until you narrow down where it’s crashing
- Tried and true “comment out code till it works” then backtrack from there :]
Let’s try it out. Go to Run\Run with Performance Tool\Leaks, and select a few rows in the table view. Also scroll up and down the table view from the top of the table to the bottom of the table. After bait of experimentation, you should start seeing some leaks popping up in the Leaks tab, which show up as blue bars.
Click the stop button, then go to the toolbar in the middle and click it to change from “Leaked Blocks” to “Call Tree”. In the panel in the lower left, click “Invert Call Tree”, and “Hide System Libraries”. You’ll see that it found two different methods in the code with memory leaks, as you can see below:
我没有看到blue bars,后面也没看到到这this two methods