Medium Programming & OOP Memory Management
How does garbage collection work in Java?
Answer
Java GC automatically reclaims memory from unreachable objects. Heap divided into generations: Young (Eden + Survivor spaces) for new objects, Old/Tenured for long-lived objects. Minor GC cleans Young generation frequently; Major GC cleans Old generation (slower). Algorithms: Serial, Parallel, CMS (deprecated), G1 (default in Java 9+), ZGC/Shenandoah (low-latency). G1 divides heap into regions, collects regions with most garbage first. GC roots: stack references, static fields, JNI references. Tuning: heap size, generation ratios, GC algorithm selection.
IIT Certified
Master These Concepts with IIT Certification
175+ hours of industry projects. Get placed at Bosch, Tata Motors, L&T and 500+ companies.
Relevant for Roles
Java Developer Backend Developer Performance Engineer