- 主题:小白提问:jvm申请内存后是不是不会还给操作系统?
赞
真高手
【 在 IcyFenix 的大作中提到: 】
: 有配置的。不过这个与收集器和版本相关,所以能否满足你的期望不好说。
:
: 在JDK 8及之前,哪怕GC之后占用内存下降,得到的内存空间也仅仅是从Used转变为Committed,在JVM一侧看这些已经是空闲内存了,但在OS一侧看来,仍然是被JVM占用的状态。
: ....................
- 来自「最水木 for iPhone13,2」
--
FROM 120.244.232.*
把内存还给os有什么用?
【 在 lindianfeng 的大作中提到: 】
: Java 12,增强 G1 垃圾收集器,使其能自动返回未用堆内存给操作系统
:
: G1 定期垃圾收集的类型根据 G1PeriodicGCInvokesConcurrent 参数的值确定:如果设置值了,G1 垃圾回收器将继续上一个或者启动一个新并发周期;如果没有设置值,则 G1 回收器将执行一个完整的 GC。在每次一次 GC 回收末尾,G1 回收器将调整当前的 Java 堆大小,此时便有可能会将未使用内存返还给操作系统。新的 Java 堆内存大小根据现有配置确定,具体包括下列配置:- XX:MinHeapFreeRatio、-XX:MaxHeapFreeRatio、-Xms、-Xmx。
: ....................
- 来自「最水木 for iPhone13,2」
--
FROM 120.244.232.*
好像说了下原因
https://bugs.openjdk.java.net/browse/JDK-8146436
This is useful for customers that want to minimize the amount of memory used by the java heap, and are willing to sacrifice some performance (induce more frequent GCs) to save that memory. When heap usage fluctuates greatly, the GC will tend to hold on to the excess heap memory longer than needed due to the the current algorithm which requires 4 full GCs before MaxHeapFreeRatio is fully honored. +UseAggressiveHeapShrink will eliminate the need to wait for 4 full GCs.
【 在 chzhang7901 的大作中提到: 】
: 把内存还给os有什么用?
:
:
: ....................
- 来自「最水木 for iPhone13,2」
--
FROM 120.244.232.*
这有风险啊
【 在 guestking 的大作中提到: 】
: 比如在k8s里面,给pod分配的起始内存1g,上限2g
: 大部分时候都是用不了那么多内存的
: 如果能还给os,那么就可以部署更多的pod
: ....................
- 来自「最水木 for iPhone13,2」
--
FROM 120.244.232.*