Track GC Memory Usage Using Instruments

Posted in |

When tracking GC memory usage it is essential to be able to examine the heap object graph. That's where Instruments comes in.

Using ObjectGraph

The GC Monitor Instruments template provides a default set of tools used to profile GC based apps. Reading the Instruments documentation is essential, but is no substitute for blind perseverance in this case. There is a lot of detail available and it takes time to figure out just what some of it means.

The ObjectGraph tool provides a snapshot based way of examining a running apps heap object graph. Unfortunately, in Xcode 3.6.2, there is no documentation. My deductions for use are as follows.

Track Pane

The Track Pane shows the used heap allocation in the top trace and the overall allocation in the bottom trace. Drag the playhead to see the numbers.

Snapshots

The ObjectGraph detail view reveals the snapshot nature of this tool. The tool defaults to taking periodic snapshots of the application's running heap object graph.

Block Filters

The Roots Only option can help you identify the graphs root objects. When combined with User Defined Only you can quickly determine which of your applications objects are rooted.

Detail Pane Search Field

Using the Detail Pane bottom search field you can quickly determine if a given class is currently alive in the graph.

Using Snapshots

When ObjectGraph takes a snapshot it places a green marker in the Track Pane. By default the ObjectGraph detail view shows all objects in the graph for all markers. So if the Track Pane contains 5 snap shot markers then the detail view will contain information on all the objects in the graph as detected by all 5 snap shots. This may not be what you require.

To view the object graph for a particular snapshot use the Inspection Range toolbar control to bracket the required snapshot marker. This enables you to detect if a particular object is present in the graph at the time the snapshot was taken.

Extended Detail view and Roots

Rooted objects are either global variables, stack variables or objects with external references.

Using the Extended Detail Pane in conjunction with the Roots Only and User-Defined Only options it is possible to see the root references for each object.

In many cases application root objects will statically allocated singletons and the Extended Detail pane will identify those.

Objects currently on the stack at the time the snapshot was taken will also be rooted. These may be reported as multiple stack roots which just indicates that references these objects are present on the heap in multiple locations, probably as a result of their use in function calls.

Submitted by Jonathan Mitchell on Tue, 01/05/2010 - 14:47

Post new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
Let us know you are human.
14 + 2 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.