Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java memory usages

Tags:

java

memory

I cannot understand the Java memory usage. I have an application which is executed with maximum memory size set to 256M. Yet, at some point in time I can see that according to the task manager it takes up to 700MB!

Needless to say, all the rest of the applications are a bit unresponsive when this happens as they are probably swapped out.

It's JDK 1.6 on WinXP. Any ideas ?

like image 275
Demiurg Avatar asked Jan 29 '26 17:01

Demiurg


2 Answers

The memory configured is available to the application. It won't include

  1. the JVM size
  2. the jars/libs loaded in
  3. native libraries and related allocated memory

which will result in a much bigger image. Note that due to how the OS and the JVM work that 700Mb may be shared between multiple JVMs (due to shared binary images, shared libraries etc.)

like image 117
Brian Agnew Avatar answered Feb 01 '26 07:02

Brian Agnew


The amount you specify with -Xmx is only for the user accessible heap - the space in which you create runtime objects dynamically.

The Java process will usea lot more space for its own needs, including the JVM, the program and other libraries, constants pool, etc.

In addition, because of the way the garbage collection system works, there may be more memory allocated than what is currently in the heap - it just hasn't been reclaimed yet.

All that being said, setting your program to a maximal heap of 256MB is really lowballing it on a modern system. For heavy programs you can usually request at least 1GB of heap.

As you mentioned, one possible cause of slowness is that some of the memory allocated to Java gets swapped off to disk. In that case, the program would indeed start churning the disk, so don't go overboard if you have little physical memory available. On Linux, you can get page miss stats for a process, I am sure there's a similar way on windows.

like image 24
Uri Avatar answered Feb 01 '26 09:02

Uri



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!