JVM是否在不再需要时向操作系统提供可用内存? [英] Does the JVM give back free memory to the OS when no longer needed?

查看:271
本文介绍了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将向OS提供额外的内存(例如,用于其他进程)。目前我的应用程序似乎永远保留了内存,即使不再需要它。

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是否在不再需要时向操作系统提供可用内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆