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 是否会将空闲内存返还给操作系统?
基础教程推荐
- 如何使用 Java 创建 X509 证书? 2022-01-01
- 降序排序:Java Map 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01