When application experience java.lang.OutOfMemoryError, it’s ideal to capture heap dump right at that point to diagnose the problem because you want to know what objects were sitting in memory and what percentage of memory they were occupying when java.lang.OutOfMemoryError occurred. However, due to the heat of the moment, most times, IT/Operations team forgets to capture heap dump. Not only that, they also restart the application. It’s extremely hard to diagnose any memory problems without capturing heap dumps at right time.
That’s where this option comes very handy. When you pass ‘-XX:+HeapDumpOnOutOfMemoryError’ system property during application startup, JVM will capture heap dumps right at the point when JVM experiences OutOfMemoryError.
Note: Captured heap dump will be printed at the location specified by ‘-XX:HeapDumpPath’ system property.