Sobes.tech
Junior

What garbage collectors (Garbage Collector) do you know?

sobes.tech AI

Answer from AI

Java uses various garbage collectors, each with its own features:

  • Serial GC: Single-threaded, suitable for small applications and client JVMs. Stops all application threads during collection (Stop-The-World or STW).
  • Parallel GC (Throughput GC): Multithreaded, optimized to increase application throughput by using multiple threads for young generation collection and one thread for old generation. Also causes STW.
  • CMS (Concurrent Mark Sweep GC): Designed to minimize pauses through concurrent phases (when the application continues to run). Has STW phases, but shorter than Serial and Parallel GC. Can lead to memory fragmentation.
  • G1 (Garbage-First GC): Divides the heap into regions. Attempts to collect garbage in regions with the most garbage ('garbage-first'). Aims for predictable pauses.
  • ZGC (Z Garbage Collector): Scalable garbage collector with very low latency (less than 10 ms) even for very large heaps (terabytes). Almost fully concurrent.
  • Shenandoah: Garbage collector with very low pauses, developed by OpenJDK. Almost fully concurrent, like ZGC.

The choice of garbage collector depends on application requirements such as throughput, latency, and heap size.