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.

To find memory leaks in your app
  1. Open the Leaks template.

  2. From the Choose Target pop-up menu in the toolbar, choose your app.

  3. Click the Record button.

  4. Exercise your app in order to execute code, and click Stop when leaks are displayed.

  5. Click any leaked object that is identified in the Detail pane.

  6. Within the Extended Detail inspector, double-click an instruction from your code.

  7. 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 weak keyword.


Related Articles