Skip to content

Most visited

Recently visited

navigation

HPROF Viewer and Analyzer

When you're monitoring memory usage in the Memory Monitor included in Android Monitor you can, at the same time, dump a snapshot of the Java heap to an Android-specific Heap/CPU Profiling (HPROF) file. The HPROF Viewer displays classes, instances of each class, and a reference tree to help you track memory usage and find memory leaks. HPROF is a binary heap dump format originally supported by J2SE.

Why Look at the Java Heap?

The Java heap display does the following:

However, you have to look for changes over time yourself by tracking what's happening in the graph.

The HPROF Analyzer finds the following potential issues:

A dominator is at the top of a tree. If you remove it, you also remove the branches of the tree it dominates, so it’s a potential way to free memory.

Understanding the HPROF Viewer Display

The HPROF Viewer looks similar to the following figure:

The tool displays the following information:

Column Description
Class Name The Java class responsible for the memory.
Total Count Total number of instances outstanding.
Heap Count Number of instances in the selected heap.
Sizeof Size of the instances (currently, 0 if the size is variable).
Shallow Size Total size of all instances in this heap.
Retained Size Size of memory that all instances of this class is dominating.
Instance A specific instance of the class.
Reference Tree References that point to the selected instance, as well as references pointing to the references.
Depth The shortest number of hops from any GC root to the selected instance.
Shallow Size Size of this instance.
Dominating Size Size of memory that this instance is dominating.

If you click Analyzer Tasks, the HPROF Analyzer appears:

You can detect leaked activities and find duplicate strings with the HPROF Analyzer.

Taking and Displaying a Snapshot of the Java Heap

To examine a snapshot of the Java heap:

  1. Display a running app in the Memory Monitor.
  2. Click Dump Java Heap Dump Java Heap icon.
  3. When the icon on the Memory Monitor display changes from Dump Java Heap Start icon to Dump Java Heap End icon, the file is ready. Android Studio creates the heap snapshot file with the filename package_yyyy.mm.dd_hh.mm.ss.hprof using the activity package (or project) name, year, month, day, hour, minute, and second of the capture, for example, com.android.calc_2015.11.17_14.58.48.hprof.

    The HPROF Viewer appears.

Viewing a Saved HPROF File

After you do a heap dump, Android Studio automatically stores it so you can view it again.

To view an HPROF file in the HPROF Viewer:

  1. Click Captures icon in the main window.
  2. Or select View > Tools Windows > Captures.

    The Captures window appears.

  3. Open the Heap Snapshot folder.
  4. Double-click the file to view it in the HPROF Viewer.
  5. The HPROF Viewer appears.

  6. Select the Heap menu option you want to display:
    • App heap - The heap used by the current app.
    • Image heap - The memory mapped copy of the current app on disk.
    • Zygote heap - The common set of libraries and runtime classes and data that all apps are forked from. The zygote space is created during device startup and is never allocated into.
  7. Select the View menu option you want to display:
    • Class List View
    • Package Tree View

Diving into Heap Dump Data in the HPROF Viewer

The following steps outline the typical workflow:

  1. In the HPROF Viewer, select a class name.
  2. Select an instance of that class.
  3. Examine the reference tree.
  4. Right-click an item to Jump to source or Go to instance, as needed.

Analyzing Heap Dump Data in the HPROF Analyzer

You can detect leaked activities and find duplicate strings with the HPROF Analyzer.

To use the HPROF Analyzer:

  1. In the Captures window, double-click an .hprof file to display it in the HPROF Viewer.
  2. Click Analyzer Tasks on the right side of the main Android Studio window.
  3. The HPROF Analyzer appears to the right of the HPROF Analyzer, by default.

  4. In the Analyzer Tasks list, select the items you want to find.
  5. Click Perform Analysis Perform Analysis icon.
  6. Examine the items in Analysis Results. Click an item to display it in the HPROF Viewer.

Sorting Heap Dump Data

To sort heap dump data:

Displaying Java Source

For some items displayed in the HPROF Viewer, you can go straight to its source code.

To display Java source:

Working with HPROF Files

You can rename, locate, and delete an HPROF file from within Android Studio. You can also convert it to standard HPROF format to use with other analysis tools.

Renaming an HPROF file

If you rename a file from within Android Studio, it continues to appear in the Captures window.

To rename an HPROF file:

  1. In the Captures window, right-click the file and select Rename.
  2. In the dialog, specify the name of the file and click OK.

Locating a heap dump file on disk

You can quickly discover where Android Studio stored HPROF files on disk.

To locate an HPROF file on disk:

Note: If you move an HPROF file, Android Studio no longer displays it in the Captures window. To display it, use File > Open. Also, if you want to rename the file, do it from the Captures window and not in the operating system file browser.

Deleting a heap dump file

To delete a heap dump file:

Converting a heap dump file to standard HPROF format

You can convert an HPROF file to standard format so you can use it outside of Android Studio with other analysis tools.

To convert an HPROF file:

  1. In the Captures window, right-click a heap snapshot file and select Export to standard .hprof.
  2. In the Convert Android Java Heap Dump dialog, specify a filename and click OK.
  3. Android Studio creates a binary HPROF file in the location you specified.

This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a one-minute survey?
Help us improve Android tools and documentation.