• Post Reply Bookmark Topic Watch Topic
  • New Topic

Using -Xmx2M but 4MB used + Max heap size is 8MB?

 
Omni Muss
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I wrote a simple application. When I run this with Java VisualVM without the -Xmx command I can see the heap size used go up to 300MB and more. If I then run the same application with the -Xmx2M argument the application runs fine till the end. However I can see that the heap size goes up to 5MB (screenshot attached). Shouldn't it have exited with an OutOfMemory exception after jumping the 2MB limit? Or the -Xmx command is more of a suggestion to the JVM? Also howcome Java VisualVM reports the Heap Size to be 8MB if I set the Max heap size to 2M.
heap.png
[Thumbnail for heap.png]
Screenshot from Java VisualVM
 
A.J. Côté
Ranch Hand
Posts: 417
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks like it is trying to keep the used heap space at 2M.

It looks like it doesn't allow your app to use more than 2M but uses some overflow to postpone garbage collector runs in order to optimize things.

Anyway, a jvm will always use quite a bit more memory on the host OS than what you give it at command line parameters when you start the jvm for optimization purposes.

Here is the top output for 2 tomcat processes using -Xmx512M



It is a matter of jvm implementations and choices made for every implementation, so it may vary.

Have a look at:
java -X
output to find out how you can fine tune things.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!