← Back to libraryQuestion 37 of 273
JavaAdvanced

Garbage Collection Algorithms

📖 Detailed Explanation:

JVM uses different GC algorithms: Serial GC (simple, single-threaded, pauses long), Parallel GC (multi-threaded, high throughput), G1 GC (balanced for heaps >2GB, predictable pauses), ZGC (ultra-low latency <10ms pauses). Choosing the right GC depends on application priorities: throughput vs latency vs memory.

🌍 Real-World Example:

Serial GC: One janitor cleaning the entire office building (complete focus but slow). Parallel GC: 10 janitors cleaning 10 rooms in parallel (faster, but requires coordination). G1 GC: Janitors focus on messiest rooms first (balanced approach).

🎯 Scenario-Based Interview Question:

What is the 'Stop-The-World' (STW) event in Garbage Collection? How do modern collectors minimize STW?