Java › Garbage Collection
How does the -XX:+HeapDumpOnOutOfMemoryError flag combined with the Eclipse Memory Analyzer's 'Leak Suspects' report help quickly triage a production OutOfMemoryError, and what's the typical first thing to check in the resulting analysis?
IntermediateAnswer
-XX:+HeapDumpOnOutOfMemoryError automatically captures a full heap dump at the exact moment an OutOfMemoryError occurs (preserving the precise memory state that caused the failure, rather than requiring a separate manual dump attempt after the fact, which might not even be possible if the JVM has already crashed or the problematic state has changed) -- Eclipse MAT's automated 'Leak Suspects' report analyzes this dump and proactively identifies the largest, most likely leak-culprit object clusters by retained size, typically the fastest first step for triage before manually exploring the dominator tree yourself, often immediately pointing to the specific class and reference chain responsible without requiring deep manual investigation.
# Ensure a heap dump is captured automatically the moment OOM occurs
java -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/dumps/ -jar app.jar
# After a production OOM crash, open the resulting .hprof file in Eclipse MAT
# and run the automated "Leak Suspects Report" as the first triage stepReal-world example A production incident where a service crashed with OutOfMemoryError is triaged within minutes rather than hours because -XX:+HeapDumpOnOutOfMemoryError had already been configured, automatically preserving the exact failure-state heap dump, and Eclipse MAT's Leak Suspects report immediately identified an unbounded session cache as the dominant memory consumer.