Quick Answer
Java GC works in generations. Eden (new objects), Survivor spaces (survived one GC), and Old Gen (long-lived objects). Minor GC: collects Eden and Survivor spaces - fast. Major/Full GC: collects Old Gen - slower, causes pause. GC algorithms: Serial (single-threaded), Parallel (throughput), G1 (balanced), ZGC/Shenandoah (low latency - sub-millisecond pauses). JVM automatically manages when GC runs.
Answer
GC removes unreachable objects. Algorithms include Mark-and-Sweep and Generational GC. Prevents memory leaks automatically.
S
SugharaIQ Editorial Team
Verified Answer
This answer has been peer-reviewed by industry experts holding senior engineering roles to ensure technical accuracy and relevance for modern interview standards.