IntelliJ IDEA 2020.2 Help

Analyze memory snapshots

Memory snapshots are useful for identifying performance problems. You can analyze the heap to locate the parts of the code that use large amounts of memory resources, and to find memory leaks. In IntelliJ IDEA, you can analyze memory snapshots in the Profiler tool window.

In IntelliJ IDEA, you can analyze memory snapshots of your application taken by the command-line profiling tool or by a third-party profiling application. The IDE doesn't provide the functionality to take memory snapshots of the applications that you develop. You can, however, take memory snapshots of the IDE itself for troubleshooting and diagnostics.

Open a memory snapshot

  1. From the main menu, select Run | Open Profiler Snapshot | Open.

  2. In the dialog that opens, select the necessary memory dump file with the .hprof extension and click Open.

Take a memory snapshot of the IDE

This action takes a snapshot of the IDE itself, not the application that you develop.

  1. From the main menu, select Help | Diagnostic Tools | Capture Memory Snapshot.

  2. When the snapshot is captured, a notification appears at the bottom of the screen. Click Open to start analyzing the snapshot in the Profiler tool window.

    If you miss the notification, you can open the IDE snapshot from the main menu.

    IDE memory snapshot is captured

    Memory snapshots are saved to the home directory on your computer.

IntelliJ IDEA opens the Profiler tool window with a memory snapshot breakdown.

A memory dump file shown in the Profiler tool window

Read a memory snapshot file

The left-hand part of the snapshot displays the list of classes in your application, how many times each class is used, its shallow size and its retained size.

Shallow size: the sum of all objects' shallow sizes, where the shallow size of an object is the amount memory allocated to store the object itself.

Retained size: the sum of the object's retained sizes. The object's retained size is the sum of the object's shallow size and the shallow size of its retained objects (objects that can be accessed only from this object).

the Classes tab of the Profiler tool window

The right-hand part of the snapshot has several tabs that allow you to calculate and display the following information:

  • The Biggest Objects tab lists objects that retain most of the memory ordered by their retained size. These objects are presented as dominator tree roots. This tab can help you find memory leaks caused by individual objects.

    Information shown on the Biggest Objects tab

  • The GC Roots tab shows garbage collector root objects grouped by classes. This information is an overview of all objects that could not be garbage collected the moment the snapshot was taken.

    Information shown on the GC Roots tab

  • The Merged Paths tab shows dominator objects that are grouped by class. For every class name, you can see the number of objects in it. This information helps understand how classes are retained.

    Information shown on the Merged Paths tab

  • The Summary tab shows general information, for example, the total size, number of instances and stack traces of the file.

    The Summary tab on Profiler tool window

Object view

The Object view displays class instances ordered by their retained size.

You can open the view by double-clicking an item on the Classes tab. You can also right-click an item and select Open in New Tab or press Enter.

A class shown in the Object view of the Profiler tool window

For each class instance, there are several tabs that allow you to calculate and display the following information:

  • Shortest Paths: the shortest reference chains to garbage collector roots for the instances that haven't been garbage collected.

  • Incoming References: incoming references from other instances.

  • Dominators: allows you to see the instances that prevents the previous instances from being garbage collected. Every instance has only one dominator or hasn't got any.

  • Retained Objects: shows objects in a way that the next level shows those objects that are immediately prevented from being garbage collected.

Productivity tips

Use speed search

On the Classes tab and in the Object view, you can use speed search.

Start typing a class name. As you type, the Search for field appears over the tool window showing the entered characters, and the selection moves to the first item that matches the specified name. For more information, refer to Speed search in tool windows.

Navigate to source

You can quickly navigate from the Profiler tool window to the corresponding line in the source code: right-click an item and select Jump to Source or press F4.

Last modified: 21 July 2020