2011年6月28日星期二

xcode instruments Allocations & Leaks

Allocations

The Allocations instrument tracks memory allocation for an application. This instrument requires that you launch a single process so that it can gather data from the start of the process.

This instrument captures the following information:

Category - typically a Core Foundation object, an Objective-C class, or a raw block of memory.
Net Bytes - the number of bytes of this type currently allocated but not yet released.
# Net - the number of objects or memory blocks of this type currently allocated but not yet released.
Overall Bytes - the total number of bytes of this type that have been allocated, including those that have been released.
# Overall - the total number of objects or memory blocks of this type that have been allocated, including those that have been released.
# Allocations (Net / Overall) - A histogram of the current and total counts. The bars are normally shades of blue. They are colored shades of yellow when the ratio between the total number of objects and the peak, or the ratio between the peak and the current number, is 1/3 or less. The bars are shades of red when the ratio is 1/10 or less.
Although the ratios displayed aren't necessarily bad (often, they're normal over the long run of an application), Instruments colors them to point out allocation patterns that may deserve a further look. If you see categories where the color is red or yellow, you might try to eliminate unnecessary temporary allocations of the given type in your application. Similarly, you might simply try to eliminate the high-water mark in the number of objects.

The data table in the details pane contains a Graph column, which contains a checkbox for each row in the table. When the checkbox for a given category is enabled, the instrument displays the graph for that particular category type in the Track pane. Instruments automatically assigns a color to each graphed category.

When you mouse over category names in the details pane, a more Info button appears next to the category name. Clicking this button displays detailed information about the objects in that category, including the following attributes:

The address of the block.
The function call or class that generated the allocation event. For example, you can see which method in a class retained an object.
The creation time of the object.
The library responsible for creating the object.
For any of these events, you can open the Extended Detail pane to see the stack trace for each object allocation, including the type of allocation and the time at which the event occurred.

For specific instances of an object (or memory block), you can click the more info button in the Object Address column to see the allocation events associated with that object. For each allocation event, this instrument displays the following information:

The category of the object (its type)
The event type.
The timestamp for each event.
The address of the block
The size of the block
The library responsible for allocating the block.
The function that caused the allocation event.
For any allocation event, you can open the Extended Detail pane to see the stack trace, as well as any available event information and the time at which the event occurred.

To further filter information in the Detail pane, you can configure the Allocation Lifespan options. These options let you filter the allocation events based on the following criteria:

All Objects Created - display all objects, regardless of whether they have been deallocated.
Created & Still Living - display only objects that existed in memory when you stopped recording data..
The inspector for the Allocations instrument lets you configure the way the instrument tracks information. From the inspector, you can set the following options:

Record reference counts. Use this option to track the reference count of each object.
Discard unrecorded data on stop. Use this option to discard any data that has been gathered but not yet processed by the Allocations instrument.
For additional information about the Allocations instrument, see “Analyzing Data with the Allocations Instrument.”

Leaks

The Leaks instrument examines a process’s heap for leaked memory. You can use this instrument together with the Allocations instrument to get memory address histories. This instrument requires that you launch a single process so that it can gather data from the start of the process.

This instrument captures the following information:

The number of leaks
The size of each leak
Address of the leaked block
Type of the leaked object
Each view mode in the Detail pane shows the leak data in a slightly different way. In table mode, this instrument shows the individual leaks along with the percentage that each individual leak contributes to the total amount of leaked memory discovered. In outline mode, the data is reorganized so that you can see how much memory is leaked from within a given symbol. For entries in either mode, the Extended Detail pane displays a heavy stack trace showing from where the leak originated.

For additional information about the Leaks instrument, see “Looking for Memory Leaks.”
发表评论