Skip to content
Ameen Abozaid
Planned lessonMID-002-L06

Memory leaks in managed languages

  • Lesson 6 of 7
  • Mid-level
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, ThreadLocal values in pooled threads, unclosed resources.
  • Symptom: old-gen floor rises across GCs; eventually OutOfMemoryError and long full GCs.
  • Raising -Xmx only delays the failure.
  • Fix the retention path: bound the cache, remove the reference.
Draft outline details

Demonstration

java
private static final Map<Long, Product> CACHE = new HashMap<>(); // never evicted

Check 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.

Lab and exercises Quiz

Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.

Continue to next lesson

Type to search levels, phases, modules and lessons.