3

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

trincot
  • 317,000
  • 35
  • 244
  • 286
Khalifa
  • 315
  • 3
  • 9

3 Answers3

3

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.

Community
  • 1
  • 1
Eugene
  • 117,005
  • 15
  • 201
  • 306
  • Thank you for the response. This is weird and annoying. It's been like two weeks dealing with the Java Heap Space error :( – Khalifa Apr 11 '17 at 13:39
1

G1GC perform whole-heap operations, such as global marking, concurrently with the application threads. This prevents interruptions proportional to heap.

Through G1GC is a new age Garbage collection algorithm, a switch from CMS or Old age garbage collection should be only made in case of following :

  • More than 50% of the Java heap is occupied with live data.
  • The rate of object allocation rate or promotion varies significantly.
  • Undesired long garbage collection or compaction pauses (longer than 0.5 to 1 second)

More details about G1 internal working can be found at : http://docs.oracle.com/javase/7/docs/technotes/guides/vm/G1.html

Subodh Karwa
  • 2,495
  • 1
  • 15
  • 13
  • 1
    I had already tried G1GC but wasn't great. The problem is the code which targeted Java 6 and lately a Migr ation to Java 8 caused many problems. But I tried -XX:GCTimeRatio=19 -XX:MinHeapFreeRatio=20 -XX:MaxHeapFreeRatio=30 from the [link](http://stackoverflow.com/questions/30458195/does-gc-release-back-memory-to-os) and it helped. – Khalifa Apr 12 '17 at 07:40
0

GC will be trigged only if the application require the additional memory. gc is expensive task and vm will decide when to run it. If you suspect your program require memory and GC is not freeing that, it is a concern. If you could share test case that demostrate this issue we will work and fix this issue.

Fairoz
  • 1,616
  • 13
  • 16