Does the JVM give back free memory to the OS when no longer needed?

后端 未结 3 1898
灰色年华
灰色年华 2020-12-06 01:36

I have an application that temporarily needs some certain amount of memory/heap for some processes. Given a reasonable value of maximum heap size to the JVM as an option, th

3条回答
  •  青春惊慌失措
    2020-12-06 02:02

    The JVM does return memory to the OS, but only very reluctantly, since it may need it again soon, and getting memory from the OS is a relatively expensive operation.

    If you want the JVM to return memory to the OS more eagerly, you can use the tuning parameters of the Oracle JVM, specifically -XX:MaxHeapFreeRatio and -XX:MinHeapFreeRatio

提交回复
热议问题