jmap
Last updated
Was this helpful?
Last updated
Was this helpful?
jmap
is a JDK utility used to generate heap dumps or analyze memory usage in a Java application. A heap dump is a snapshot of the JVM's memory, including all objects and references at a specific point in time. It is essential for diagnosing memory leaks, OutOfMemoryError
, or high memory usage.
Diagnosing memory leaks by analyzing objects and their references.
Understanding the distribution of objects in memory.
Debugging OutOfMemoryError
issues.
Use the jps
command to locate your Spring Boot app’s PID:
Output example:
Start the Java Application (here it is sample-print-service maven springboot application)
jps
command output is below
Here, 83322
is the PID of our Springboot app.
Run the following jmap
command to generate a heap dump:
format=b
: Specifies the binary format for the dump file.
file=heap-dump.hprof
: Specifies the file name for the heap dump.
The heap-dump.hprof
file will be saved in the current directory.
Use tools like Eclipse MAT (Memory Analyzer Tool) or VisualVM to open and analyze the heap-dump.hprof
file.
Look for objects with high retention, large collections, or unreferenced objects.
Detect memory leaks by identifying objects that cannot be garbage collected.