Memory leaks in managed languages
On This Lesson 4 topics
This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.
In this lesson
recognize how leaks happen with a GC.
Planned topics
- A Java leak is an object that is still reachable but no longer needed.
- Classic sources: unbounded caches, static collections, listeners never removed,
ThreadLocalvalues in pooled threads, unclosed resources. - Symptom: old-gen floor rises across GCs; eventually
OutOfMemoryErrorand long full GCs. - Raising
-Xmxonly delays the failure. - Fix the retention path: bound the cache, remove the reference.
Draft outline details
Demonstration
private static final Map<Long, Product> CACHE = new HashMap<>(); // never evictedCheck your understanding
Why does the GC not free the leaked entries?
Show answer
They are still reachable through the static map.
Practice
Apply this lesson with the module's lab, exercises and quiz.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.