Skip to content

Browser leaks overview

Browser tabs are long-lived. Unlike a stateless HTTP request, an SPA may run for hours. Small leaks compound.

Pattern Mechanism Lesson
Accidental globals Assignment without let/const Global variables
Forgotten timers setInterval + closure Timers
Detached DOM Removed from tree, kept in JS Detached DOM
Listeners addEventListener without removal Event listeners
Closures Callback retains outer scope Closures
Unbounded cache Map/{} never evicts Unbounded cache
flowchart LR
  SPA[SPA session hours]
  leak[Small leak per navigation]
  SPA --> leak
  leak --> crash[Tab slow / killed]

Each lesson below includes a live demo with a real-time heap chart (Chrome). Workflow:

  1. Open lesson in Chrome
  2. Click Start leaking — watch chart climb
  3. Click Stop & fix — release references
  4. Optionally force GC in DevTools and watch recovery

Open DevTools → Performance monitor (More tools) → watch JS heap size while repeating an action (navigate, open modal, etc.). If heap stair-steps upward without returning to baseline, investigate.