freecoding.school100% FREE · NO SIGNUP
API ArcadeISSUE #22 of 23

memory · the v8 heap · gc cycles

ApiaVSLegacy Larry
Apia saysJS manages memory automatically with garbage collection — but leaks still happen via stray references.

The engine (V8) frees memory once nothing references an object — you don't free() manually. Leaks come from unintended references that keep objects alive: forgotten timers/listeners, growing global caches, closures holding big data, detached DOM nodes. The DevTools Memory panel (heap snapshots) finds them. Clean up listeners and intervals you create.

Power-ups you unlock

Legacy Larry attacks — common mistakes

Boss battleName three things that keep an object alive and cause a leak.

Example code

<!doctype html><html><head><meta charset="utf-8"></head>
<body style="background:#06040d;color:#e6e0ff;font-family:monospace;padding:20px"><pre>// leaks to avoid:
setInterval(() => bigArray.push(x), 100); // never cleared
el.addEventListener('click', handler);     // never removed
globalCache[key] = hugeObject;             // never evicted
// → clear intervals, remove listeners, bound caches</pre></body></html>
▶ Open the interactive comic issue
‹ Performance · Profiling · DevtoolsReferences · Examples · Exercises · Certificate ›