Memory leaks happen often and at times become tricky to reproduce. It’s worth while to generate Heap dump when an OOME occurs. Let’s see how what are the command line options that controls them.
Add the following options to command line while launching the Java Application
-XX:+HeapDumpOnOutOfMemoryError – Tells JVM to generate Heap dump on OOME
-XX:HeapDumpPath – Specify the path where Heap dump is to be generated
Let’s see a sample
java -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/tmp MyApp