0

Does the JVM ever give memory back to the OS it has previously allocated for the heap?

For example, I have a JVM that at set to -Xmx5120M and I have actually used all of that memory, doing stuff that would cause the heap to fill up. Lets say a full GC happens, which brings actual heap usage down significantly. Will that drop cause the total heap size to be reduced, presumably to just above actual usage levels, and the "cleared" memory is returned to the OS? Or will the memory allocated to the JVM remain at the high level even though it may not be "actively" using all of it in the heap now.

Slim down vs hoard I guess.

EDIT: I'm interested in the Sun/Oracle JVM (i.e. 1.6.0_33, 1.7+ or the like)

h1d3m3
  • 51
  • 5
  • I bet it doesn't "return" unused memory back to the OS, but even if so - it's per JVM implementation – Nir Alfasi Aug 23 '13 at 22:01
  • 2
    Is this the same answer to your question? http://stackoverflow.com/questions/2419247/java-vm-does-the-freed-memory-return-to-the-os – Alexander Lin Aug 23 '13 at 22:01
  • For most JVMs the answer is *no*. But there's probably some JVM somewhere that *does* return storage to the OS. – Hot Licks Aug 23 '13 at 22:19

0 Answers0