Course
Free until 31 October

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
Prefer video?
Curriculum
  1. 01
    Stack vs heap
    The stack runs your code. The heap holds your data.
  2. 02
    References and the object graph
    Log in
    An object stays alive as long as something can reach it.
  3. 03
    GC roots and reachability
    Log in
    If a root can reach it, it stays alive.
  4. 04
    Young generation and minor GC
    Log in
    Most objects die young, so only the survivors cost anything.
  5. 05
    Major GC: mark, sweep, compact
    Log in
    How V8 cleans the old generation in three steps.
  6. 06
    How GC avoids freezing the page
    Log in
    Four ways to schedule GC work, measured against a 16 ms frame.
  7. 07
    How memory leaks happen
    Log in
    The component left. Its data didn't.
  8. 08
    Weak references and WeakMap
    Log in
    A reference that doesn't keep objects alive.
  9. 09
    Finding leaks with heap snapshots
    Log in
    Snapshot, repeat, compare, then follow the retainers.