I would like to specify amount of memory used when -XX:+HeapDumpOnOutOfMemoryError VM argument is used. Normally, I control the heap size using -Xmx<size> VM argument. But when I do that the out of memory error never occurs. Does anybody know a way to specify such a parameter so that when the heap size (or even the stack size) reaches that parameter the out of memory error is thrown and I can get the heap dump?
Thanks.
-Xmxis the right way to do this along with-Xssfor the stack size to cause aStackOverflowException. If you don’t get the expectedOutOfMemoryErroryou might need to try lower values for-Xmxsince the JVM tends to go somewhat beyond that limit before it throws the error and it seems to ignore anything below 15m for-Xmx.