Challenge 04 — Forgotten setInterval

Find why memory grows from an uncleared interval.

Mission

Idle — each interval tick retains a growing closure scope.

DevTools checklist

  1. Take snapshot (A)
  2. Click Start leaking — wait ~10 seconds
  3. Force GC → snapshot (B) → Comparison
  4. Look for system / Context and Array growth

Expected signals

  • Array instances accumulate
  • system / Context or closure-related entries grow
  • Retainers trace through the interval callback closure

Hints & solution

Hint

A timer keeps firing and the callback closure holds onto every array it has ever created.

Solution

setInterval runs every 400ms, pushing large arrays into retained inside the callback scope. Without clearInterval, the closure never releases them.

// Fix: clear the interval on cleanup
const id = setInterval(() => { /* ... */ }, 400);
clearInterval(id);

← Lesson: Forgotten timers · All challenges