前言
公司有一个系统使用的是CMS垃圾回收器,JVM初始堆内存不等于最大堆内存,但通过监控信息发现:在经过一次FullGC之后,服务器物理内存剩余空间并未提升,按照我之前的理解FullGC之后JVM进程会释放的内存一部分还给物理内存,下面通过几个实验来对比验证一下CMS和G1的物理内存归还机制
测试代码
public class MemoryRecycleTest {
static volatile List<OOMobject> list = new ArrayList<>();
public static void main(String[] args) {
//指定要生产的对象大小为512M
int count = 512;
//新建一条线程,负责生产对象
new Thread(() -> {
try {
for (int i = 1; i <= 10; i++) {
System.out.println(String.format("第%s次生产%s大小的对象", i, count));
addObject(list, count);
//休眠40秒
Thread.sleep(i * 10000);
}
} catch (InterruptedException e