Finding Memory Leaks in Your App
Use the Leaks instrument of the Instruments analysis tool to find objects in your app that are no longer referenced and reachable.
Open the Leaks template.
From the Choose Target pop-up menu in the toolbar, choose your app.
Click the Record button.
Exercise your app in order to execute code, and click Stop when leaks are displayed.
Click any leaked object that is identified in the Detail pane.
Within the Extended Detail inspector, double-click an instruction from your code.
In the detail pane, click the Xcode icon to open that code in Xcode.
Click the Leaks instrument in the Instruments pane to display leaks in the detail pane. The Leaks graph shows you the number of leaks and the total leaked bytes.
If the leaked memory is an Objective-C object, then pressing the focus arrow next to the address of an individual object will show the retain/release history of the object with corresponding stack traces for each event.
Non-object leaks are the result of calling
malloc() without a corresponding
free() and thus only the stack trace of the allocation event is presented.
The Leaks by Backtrace view aggregates all of the leaked blocks by their allocation point — a single mistake in source code can result in multiple runtime leaks as the code is executed repeatedly.
The Cycles & Roots view is important when writing apps using Automatic Reference Counting (ARC) as it gives a graph-level view of leaked objects, aiding in the diagnosis of retain cycles. Frequently the solution to these problems will be marking an up-reference in the object graph with the