-XX:+HeapDumpOnOutOfMemoryError specify memory
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开发者_如何学C 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.
-Xmx
is the right way to do this along with -Xss
for the stack size to cause a StackOverflowException
. If you don't get the expected OutOfMemoryError
you might need to try lower values for -Xmx
since the JVM tends to go somewhat beyond that limit before it throws the error and it seems to ignore anything below 15m for -Xmx
.
To answer your question more precisely than what was provided by x4u, it would help to know the following:
Question #1: When you explicitly set -Xmx
, what are you setting it to? What is the difference between the two heap sizes (with and without -Xmx
). I'm assuming you're increasing the heap size when you set it explicitly.
Question #2: Does your program terminate, or run forever? If it terminates and you're not seeing the OOM, it could be that you don't have a leak, you're just not providing enough memory to your Java process.
精彩评论