[Interview Questions] What are the garbage collectors in JVM?

Sometimes the content of the blog will change. The first blog is the latest. Other blog addresses may not be synchronized. Please check it carefully.https://blog.zysicyj.top

First blog address

Series article address


In the Java Virtual Machine (JVM), there are the following common garbage collectors:

  1. "Serial Collector" : The Serial collector is the most basic garbage collector, which uses a single thread for garbage collection. It uses the "mark-copy" algorithm to divide the heap memory into the young generation and the old generation, and performs garbage collection by copying surviving objects. The Serial collector is suitable for single-threaded environments and small applications.

  2. "Parallel Collector" : The Parallel collector is a multi-threaded version of the Serial collector, which uses multiple threads to perform garbage collection in parallel. It also uses a "mark-copy" algorithm, but compared to the Serial collector, the Parallel collector can complete garbage collection faster. Parallel collector is suitable for multi-core processors and applications requiring high throughput.

  3. "CMS Collector" : The CMS (Concurrent Mark Sweep) collector is a concurrent garbage collector that uses the "mark-sweep" algorithm for garbage collection. The CMS collector reduces the pause time caused by garbage collection through concurrent marking and concurrent cleaning. It is suitable for applications requiring low latency.

  4. "G1 Collector" : The G1 (Garbage-First) collector is a garbage collector for large heaps of memory. It uses generational collection and regionalized memory layout. The G1 collector achieves low-latency and high-throughput garbage collection through concurrent marking and concurrent clearing, and by preferentially recycling areas with the most garbage. It is suitable for large applications and applications that require predictable pause times.

  5. "ZGC Collector" : The ZGC collector is a low-latency garbage collector. Its goal is to reclaim as much memory as possible within a pause time of no more than 10 milliseconds. The ZGC collector uses a memory layout called "Region" to divide the heap memory into multiple equal-sized regions. It tracks object reference relationships through concurrent marking and concurrent cleaning, as well as read barriers and write barriers. The ZGC collector is suitable for applications requiring fast response and high throughput.

  6. "Shenandoah Collector" : The Shenandoah Collector is a concurrent garbage collector whose goal is to reclaim as much memory as possible within a pause time of no more than 10 milliseconds. The Shenandoah collector uses a data structure called a "Remembered Set" to track object reference relationships. It ensures the concurrent execution of the garbage collector and the application through concurrent marking and concurrent cleaning, as well as read barriers and write barriers. The Shenandoah collector is suitable for applications that require fast response and high concurrency.

If you like my content, please click follow

Scan the QR code and long press to follow the communication group to get the latest news. The free interview question manual will be launched in the communication group soon.

alt

No public

alt

Personal WeChat

alt

This article is published by mdnice multi-platform

Guess you like

Origin blog.csdn.net/njpkhuan/article/details/132844618