Search code examples
memory-managementjava-8garbage-collectionheap-memoryjvm-hotspot

Release Java Heap Sapce


I have an issue with java performance. I tried using GC1 but it didn't make things great. My only question is why the JVM keeps the java heap space even if it's not used ? As you can see in the picture first the batch work finish around 10:30 but the garbage collector wasn't triggered to clean. So I did it manually at 10:52 then the used space was freed but heap (8GB) is still allocated by the JVM. Why ? Java Memory Problem


Solution

  • I've seen this trend too while doing the exact same thing that you did (and see here). The explanation is quite simple: JVM will not give back memory to the OS, even if it has lots of it free. I don't know the exact details of why this is so, but it has to do with the fact that asking memory back from the OS is expensive (this is ultra-simplified).

    So I guess that the simple answer here is that - this is normal.

    Here it is! I found where I have actually read about this.