Does the JVM give back free memory to the OS when no longer needed?(当不再需要时,JVM 是否会将空闲内存返还给操作系统?)
问题描述
我有一个应用程序暂时需要一定数量的内存/堆用于某些进程.给定一个合理的 JVM 最大堆大小值作为选项,JVM 从一个小堆开始,并根据需要向操作系统请求更多内存.
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, the JVM starts with a little heap and requests more memory from the OS on demand.
我的问题是,当我的应用程序不再需要太多内存时,JVM 是否会将额外的内存返还给操作系统(例如,用于其他进程).目前,我的应用程序似乎永远保留了该内存,即使不再需要.
My question is, if that additional memory will be given back by the JVM to the OS (e.g. for other processes) when there is no need for much memory anymore by my application. Currently my application seems to hold that memory forever, even when not needed anymore.
推荐答案
JVM确实将内存返回给操作系统,但只是很不情愿,因为它可能很快又需要它,而从操作系统获取内存是一个相对昂贵的操作.
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.
如果您希望 JVM 更急切地将内存返回给操作系统,您可以使用 Oracle JVM的调优参数,具体是-XX:MaxHeapFreeRatio
和-XX:MinHeapFreeRatio
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
这篇关于当不再需要时,JVM 是否会将空闲内存返还给操作系统?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:当不再需要时,JVM 是否会将空闲内存返还给操作系统?


- Eclipse 插件更新错误日志在哪里? 2022-01-01
- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01
- Java包名称中单词分隔符的约定是什么? 2022-01-01
- 如何使用WebFilter实现授权头检查 2022-01-01
- 将log4j 1.2配置转换为log4j 2配置 2022-01-01
- 从 finally 块返回时 Java 的奇怪行为 2022-01-01
- Jersey REST 客户端:发布多部分数据 2022-01-01
- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01
- C++ 和 Java 进程之间的共享内存 2022-01-01
- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01