All courses
Course · Free
JavaScript Memory and Garbage Collection
Find out what keeps an object alive, why apps leak memory, and how the browser cleans up without freezing the page.
9
Lessons
69
Steps
About 1 hour
Duration
Your own
Pace
Short on time? Read the recap and interview answers
Prefer video?
Curriculum
- 01Stack vs heapThe stack runs your code. The heap holds your data.
- 02References and the object graphLog inAn object stays alive as long as something can reach it.
- 03GC roots and reachabilityLog inIf a root can reach it, it stays alive.
- 04Young generation and minor GCLog inMost objects die young, so only the survivors cost anything.
- 05Major GC: mark, sweep, compactLog inHow V8 cleans the old generation in three steps.
- 06How GC avoids freezing the pageLog inFour ways to schedule GC work, measured against a 16 ms frame.
- 07How memory leaks happenLog inThe component left. Its data didn't.
- 08Weak references and WeakMapLog inA reference that doesn't keep objects alive.
- 09Finding leaks with heap snapshotsLog inSnapshot, repeat, compare, then follow the retainers.



