Try the search, it's linked to some great forums

Friday, January 11, 2013

Memory leaks

Even with ARC (Automatic Reference Counting) an app can have memory leaks which can totally foul up an app.  Typical signs of leaks include;
  • slowing of the apps animation, view transitions, etc
  • locking up the app and or device (see Turning off your locked up iPad)
This post is a quickstart guide for using Xcode's Instruments specifically  to find those leaks.
From within Xcode;
  • Select Xcode-Open Developer's Tools-Instrument
  • Then select your instrument from the popup - Leaks in our case
  • Size the Allocation & Leaks strip charts appropriately and
  • from the List box in the upper left select Choose Target-appName on the device
  • Press Record n Stop button to start & stop the app
Allocations should reach some level & then stop.  If you have leaks they show as red bars, and the allocations count will keep rising.  You can isolate where the leaks are by looking into the stack when the leaks occur.  Fix and rerun the app.

Apple's Instruments User Guide is the place to start learning about these tools. Also see the Xcode 4 User Guide to use with Xcode.

Within Xcode the call stack can be investigated from the Debugger toolbar as in this snapshot


 Stepping back thru the vertical call stack can give an indication where the code failed.