DEV Community

Truman
Truman

Posted on • Edited on

ZGC的两种主要的GC类型

在ZGC(Z Garbage Collector)中,有两种主要的垃圾收集类型:Major Collection和Minor Collection。具体如下:

  • Major Collection
    • Warmup Collections: 当JVM刚启动时,ZGC会进行几次Major Collection作为预热。这些预热的Major Collection帮助JVM和ZGC为后续的垃圾收集做好准备。
    • Proactive Collections: 这种类型的Major Collection是由ZGC自动触发的,以确保系统在内存使用量较高之前就开始垃圾收集,从而避免内存不足的情况。这些垃圾收集通常是预测性的,以保持系统稳定性和响应速度。
    • Mixed Collections: 在启用了Generational ZGC的情况下,Major Collection不仅会处理老年代的垃圾,还会同时处理年轻代和老年代的垃圾对象。这种方式可以提高垃圾收集的效率和性能。
  • Minor Collection
    • Young Generation Collection: 在启用了Generational ZGC的情况下,Minor Collection主要处理年轻代(Young Generation)的垃圾对象。年轻代对象通常是生命周期较短的对象,通过Minor Collection可以快速回收这部分内存。
    • Concurrent Young Generation Collection: 这是ZGC在后台进行的年轻代垃圾收集,通常是并发进行的,以减少对应用程序运行的影响。通过并发处理,ZGC可以在应用程序运行时收集垃圾对象,从而提高系统的响应速度和效率。

总结:

Major Collection主要包括:预热收集(Warmup Collections)、主动收集(Proactive Collections)和混合收集(Mixed Collections)。

Minor Collection主要处理年轻代(Young Generation)的垃圾,包括并发收集(Concurrent Young Generation Collection)。

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more