Creating Heap Dump on Linux: A Step-by-Step Guide

To obtain a heap dump, one can use the command line “java/bin/jmap -heap:format=b”. The dump can then be analyzed using various tools, such as the standard jhat tool or GUI applications like MAT. Another option is to use code that can take a heap dump over JMX. To examine the heap, a simple tool like VisualVM, which is included with the JDK, can be used.

Solution 1:

Mistaking an exception or error being thrown for a JVM crash is creating confusion.

A crash in the JVM is caused by an internal error, which is not possible to induce with a regular Java program, or at least it should not be attempted unless a bug is discovered.

Your actions are causing an Error, which allows the program to keep running until all non-daemon threads have exited.

VisualVM, which is included in the JDK, is the easiest instrument to investigate the heap. To induce a heap dump when encountering an OutOfMemoryError, utilize



Solution 2:

Use Jmap

jmap [options] pid

The application’s process id is represented by pid.

Solution 3:

When you see the below

Exception in thread "main" java.lang.OutOfMemoryError

This implies that the exception handler is responsible for dealing with your error or exception, and it should be noted that this is not a crash.

Frequently Asked Questions