Taking Heap Dump to See Memory Usages

This section provides a tutorial example on how to take a heap dump with Java VisualVM to get a snapshot of all objects in the heap with their contents.

What Is Heap Dump? A heap dump is a snapshot of all objects in the heap memory of the JVM. Heap dump helps you to understand what's going on in the JVM in terms of objects and memory usage. For example, if your Java application is having a high memory usage, you can take heap dump to find out which types of objects are using more memory and why they are not freed by the garbage collectors.

Java VisualVM can help you to create a heap dump file at any time.

1. Start Java VisualVM and connect to the running JVM of LongSleep.java.

2. Click on the Monitor tab. The monitor screen is displayed.

3. Click on the "Heap Dump" button. Java VisualVM will start to create a heap dump. It may make a long time and use large disk space, if your application is using a large memory size.

4. When the heap dump is created, Java VisualVM will show its basic info first:

File: C:\Users\herong\AppData\Local\Temp\visualvm.dat\localhost_2724
File size: 5.3 MB

Total bytes: 2,960,505
Total classes: 1,434
Total instances: 58,894
Classloaders: 65
GC roots: 1,290
Number of objects pending for finalization: 0

5. Right-mouse click on "[heapdump]..." under "LongSleep..." in the Application panel. Then select "Save As..." to save the heap dump to a file, heap_dump.hprof, for later use.

Note that a heap dump is a binary file. You need to use Java VisualVM or other heap dump tools to open it.

Last update: 2015.

Table of Contents

 About This Book

 Java Tools Terminology

 Installing Java 8 on Windows

 'javac' - The Java Program Compiler

 'java' - The Java Program Launcher

 'jdb' - The Java Debugger

 'jconsole' - Java Monitoring and Management Console

 'jstat' - JVM Statistics Monitoring Tool

 JVM Troubleshooting Tools

jvisualvm (Java VisualVM) - JVM Visual Tool

 What Is jvisualvm (Java VisualVM)?

 jvisualvm Command to Open Dump Files or Conections

 Connecting Java VisualVM to a Local JVM Process

 Monitoring Usgaes of CPU, Heap, Classes and Threads

 Monitoring Thread Status as Timeline

 Taking Thread Dump to See Thread Stack Traces

Taking Heap Dump to See Memory Usages

 Viewing a Heap Dump File

 Connecting to Remote JVM Processes

 Avaible Plugins and Installation

 Installing Visual GC Plugin

 'jar' - The JAR File Tool

 'javap' - The Java Class File Disassembler

 'keytool' - Public Key Certificate Tool

 'native2ascii' - Native-to-ASCII Encoding Converter

 Outdated Tutorials


 PDF Printing Version