Using the Heap Window

The Heap window displays information about the heap in the program you are debugging and helps you to detect memory leaks in your program. You can view all instances of a class as well as why an object has not been garbage collected.

Note: Only the Oracle Java Virtual Machine (OJVM) provides heap information. Heap information is not provided by Sun Microsystem's Java Platform Debugger Architecture (JPDA), the debugging protocol used with the Classic and HotSpot Java Virtual Machines. If you are using either the Classic or the HotSpot virtual machine (the VM is specified in the Run/Debug page of the Project Properties dialog), the Heap window will not be able to provide any information about the heap in the program you are debugging.

There are two types of folders displayed in the Heap window:

Class Folder
Displays the name of the class and how many instances of the class exists in memory, and when expanded lists the specific instances and their addresses in the heap.
 
Reference Path Folder
Contains all the "root" references which point, either directly or indirectly, to a specific object. Root references are static fields, stack variables, pinned objects. The garbage collector will not discard an object if there are any root references. Expanding a root reference will show you the reference path from the root reference to the specified object.

For more information about this window including its context menu options, press F1 or click Help in the Heap window.

To open and use the Heap window:

  1. Open source files in the Source Editor and set breakpoints.

  2. In the toolbar, click debug_toolbar_icon Debug.

  3. When the debugger hits the breakpoint, select View then choose Debug Windowsthen choose Heap from the main menu.
    The Heap window appears.

  4. Right-click in the Heap window and choose Add Class Folder from the context menu. Alternatively, drag a class node from the Classes window into the Heap window. Or, right click on a class node in the Classes window and choose Show In Heap from the context menu.
    Information about the classes appears in the Heap window.


Related topics

About Debugger Windows
Setting Preferences for the Debugger Windows
Running Java Programs
Configuring Your Project for Running
Configuring Your Project for Debugging