Guides and Sample Code

Developer

Instruments User Guide

Monitor Memory Usage

Use the Activity Monitor profiling template to track your app’s real and virtual memory use in comparison to other processes running on the system.

To create a trace document to monitor overall memory usage
  1. Launch Instruments.

  2. In the profiling template selection dialog that appears, click Activity Monitor.

  3. Choose your device and app from the target device and process lists.

  4. Click Choose to create a trace document.

The Activity Monitor profiling template includes the Activity Monitor instrument, which is preconfigured to display system load and virtual memory size. You can enable other memory-related statistics for viewing via the inspector pane.

To enable display of Activity Monitor memory statistics
  1. Press Command-1 to display the record settings area of the inspector pane (if it’s not already opened).

  2. In the statistics to list area of the inspector, select the memory-related statistics you want to see.

    The following memory-related statistics are available for display:

    • Physical Memory Wired—The amount of memory being used by the operating system.

    • Physical Memory Active—The amount of memory being used by processes other than the operating system.

    • Physical Memory Inactive—The amount of memory that was recently released.

    • Physical Memory Used—The total amount of memory that was used while performing the sample.

    • Physical Memory Free—The amount of available memory.

    • Total VM Size—The total size of virtual memory.

    • VM Page In Bytes—The amount of memory calls sent to RAM.

    • VM Page Out Bytes—The amount of memory calls sent to disk.

    • VM Swap Used—The amount of memory called from disk.

  3. In the system statistics area, select the memory-related statistics you want to see. If desired, click the shape or color controls to change how the statistics are represented in the timeline.

To gather overall memory usage detail
  1. Click the Record button (image: ../Art/inline_record_button_2x.png) in the toolbar or press Command-R to begin recording.

  2. Use your app normally.

    As the Activity Monitor instrument profiles your app, it performs samples at periodic intervals and displays the results in the timeline and detail panes.

  3. Click the Stop button (image: ../Art/inline_stop_button_2x.png) in the toolbar or press Command-R again when you’re ready to stop recording.

The timeline pane provides a graphical representation of the data collected. Scroll through the timeline to gain an understanding of how memory is being used by your app and other processes running on the system. For more detailed analysis, explore the results in the detail pane.

To view summarized memory usage by sample
  1. Click the Activity Monitor track in the timeline.

  2. Choose Samples from the detail type list in the navigation bar of the detail pane.

To view detailed memory usage by a process at a specific point during profiling
  1. Click the Activity Monitor track in the timeline.

  2. Press Command-2 to display the display settings area of the inspector pane (if it’s not already opened).

  3. In the process detail tracking area of the inspector, click “Track inspection head” to configure the detail pane to display results based on the currently selected area in the timeline, rather than the latest sample performed.

  4. Select a point in the timeline to view the statistics that were captured at that time.

  5. View memory usage statistics in the detail pane.

    Use the detail type list to toggle between a summary view of the collected data by process or a parent child view.