This question already has an answer here:
这个问题在这里已有答案:
- Does GC release back memory to OS? 4 answers
GC是否将内存释放回操作系统? 4个答案
I am using GC options XX:+UseParNewGC-XX:+UseConcMarkSweepGC
for my application.
我正在使用GC选项XX:+ UseParNewGC-XX:+ UseConcMarkSweepGC用于我的应用程序。
As most of you are already experiencing JVM is good at increasing heap up to max heap size, however it does not release memory back to OS. I came across -XX:MaxHeapFreeRatio
and -XX:MinHeapFreeRatio
but these are ignored for Parallel Garbage Collectors.
正如大多数人已经体验到的那样,JVM擅长将堆增加到最大堆大小,但它不会将内存释放回操作系统。我遇到了-XX:MaxHeapFreeRatio和-XX:MinHeapFreeRatio但是对于并行垃圾收集器,这些都被忽略了。
Are there special options to force JVM release memory back to OS for -XX:MaxHeapFreeRatio and -XX:MinHeapFreeRatio
combination.
是否有特殊选项可将JVM释放内存强制回OS-Max:MaxHeapFreeRatio和-XX:MinHeapFreeRatio组合。
1 个解决方案
#1
On my Java 1.8.0_45 -XX:+UseG1GC makes memory shrink. This is my test:
在我的Java 1.8.0_45 -XX上:+ UseG1GC使内存缩小。这是我的测试:
MemoryPoolMXBean m = ManagementFactory.getMemoryPoolMXBeans().get(5);
System.out.println(m.getName());
byte[] a = new byte[512 * 1024 * 1024];
System.out.println(m.getUsage().getCommitted() / 1024 / 1024);
a = null;
System.gc();
Thread.sleep(1000);
System.out.println(m.getUsage().getCommitted() / 1024 / 1024);
#1
On my Java 1.8.0_45 -XX:+UseG1GC makes memory shrink. This is my test:
在我的Java 1.8.0_45 -XX上:+ UseG1GC使内存缩小。这是我的测试:
MemoryPoolMXBean m = ManagementFactory.getMemoryPoolMXBeans().get(5);
System.out.println(m.getName());
byte[] a = new byte[512 * 1024 * 1024];
System.out.println(m.getUsage().getCommitted() / 1024 / 1024);
a = null;
System.gc();
Thread.sleep(1000);
System.out.println(m.getUsage().getCommitted() / 1024 / 1024);