0

I am using an in memory h2 database with the following configuration:

jdbc.url=jdbc:h2:mem:myDb;DB_CLOSE_DELAY=-1
hibernate.dialect=org.hibernate.dialect.H2Dialect
jdbc.user=sa
jdbc.pass=

I can see that the used memory on the system keeps on decreasing. And as soon as I restart the application, the memory comes back. I got the memory dump but it does not show any running threads that are occupying lot of memory. I am guessing this is because of the h2 database.

I checked the jmap result and it shows the following:

BEFORE:

enter image description here

The result of free command

I tried to use h2 shutdown and manually call the System.gc(). That helps the jmap as shown below:

AFTER:

enter image description here

However, the freed memory never reaches the OS/system. Neither the used memory goes down NOR the free memory increases !!

enter image description here

What am I missing here ? If the memory keeps increasing, my machine will always keep crashing after running for few days ? Cannot keep restarting every 2 days !

Crusaderpyro
  • 2,163
  • 5
  • 29
  • 53
  • 1. Freeing Java Heap does not necessarily [releases memory back to the OS](https://stackoverflow.com/questions/30458195/does-gc-release-back-memory-to-os). 2. The memory consumed by a Java process is not limited only by the heap. There are [much more things](https://stackoverflow.com/questions/53451103/java-using-much-more-memory-than-heap-size-or-size-correctly-docker-memory-limi/53624438#53624438) that can take memory, some not even under your control. – apangin Aug 31 '19 at 00:39
  • So there’s free memory within the heap even though it shows 4.2G used. The buff/cache memory which is outside java is taking almost 1.5G. Will this cache memory be freed when the application needs it ? – Crusaderpyro Aug 31 '19 at 12:50

0 Answers0