Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem that JVM free heap memory is not released back to OS

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

Today, I will talk to you about how to solve the problem that JVM free heap memory is not released back to OS. Many people may not know much about it. In order to make you understand better, the editor has summarized the following for you. I hope you can get something according to this article.

JDK 8 and earlier

In these versions, there is no explicit option for immediate recycling, but you can make GC generally more aggressive by setting it, which-XX:GCTimeRatio=19-XX:MinHeapFreeRatio=20-XX:MaxHeapFreeRatio=30 will make it spend more CPU time after GC to collect and limit the amount of heap memory that has been allocated but not used. Cycle.

If you use a concurrent collector, you can also set-XX:InitiatingHeapOccupancyPercent=NN to a low value so that GC runs concurrent collections almost continuously, which consumes more CPU cycles but shrinks the heap faster. Usually this is not a good idea, but on some types of computers with a large number of spare CPU kernels but out of memory, it makes sense.

If you are using G1GC, note that it only uses jdk8u20 to get the ability to return unused blocks in the middle of the heap, while previous versions can only return blocks at the end of the heap, which has a significant limit on the number of blocks that can be loaded. Take back.

If you are using a collector that has a default pause time target (such as CMS or G1), you can also relax that target to impose fewer constraints on the collector, or you can switch parallel collectors to give priority to space consumption in pause time.

To verify whether shrinkage occurs or to diagnose why GC decided not to shrink, you can use GC Logging-XX:+PrintAdaptiveSizePolicy to provide insights, for example, when JVM tries to use more memory for the younger generation to meet certain goals.

JDK 9

Added-XX:-ShrinkHeapInSteps can be used to more actively apply options that are scaled down by the options mentioned in the previous section. Related OpenJDK error.

For logging-XX:+PrintAdaptiveSizePolicy has been replaced with-Xlog:gc+ergo

JDK 12

The option of enabling instant memory freeing for G1GC via G1PeriodicGCInterval (JEP 346) is introduced, but at the expense of some additional CPU. JEP also mentions similar features in Shenandoah and OpenJ9 VM.

If you use the G1 collector and occasionally call System.gc () (which I do every minute), Java will reliably shrink the heap and return memory to OS.

Starting with Java 12, G1 does this automatically if the application is idle.

I recommend using these options in conjunction with the above recommendations to achieve a very compact resident process size:

-XX:+UseG1GC-XX:MaxHeapFreeRatio=30-XX:MinHeapFreeRatio=10JDK 13

ZGC, released in 13 Java, returns unused heap memory to the operating system, see link

After reading the above, do you have any further understanding of how to solve the problem that JVM free heap memory is not released back to OS? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report