Call Stack, Heap and Garbage Collection
- The call stack. The stack holds the frames of every function currently running: and overflows when recursion never stops.
- The heap. Objects, arrays and closures live in the heap, the big memory area the engine manages for you.
- Garbage collection. The garbage collector frees objects nothing can reach anymore: you never free memory, you release references.
References and Memory Behaviour
- Reachability. An object stays alive while any reference path leads to it: from a variable, a property, or a closure.
- Accidental retention. A forgotten listener or an ever-growing cache keeps objects reachable forever: the classic JavaScript memory leak.
- WeakMap. A WeakMap holds keys weakly: when nothing else references the key object, its entry can be collected.
Finding Memory and Runtime Problems
- Heap snapshots. A heap snapshot lists every live object by type and size: compare two to see what grew and who holds it.
- Timeline profiling. A memory timeline that climbs across repeated actions and never falls after collection is a leak in motion.
- Long tasks. Any callback holding the thread past about fifty milliseconds is a long task the profiler will name for you.
Before and after this level
- Before: Level 12: Advanced Language Patterns: Iterators and Generators, Symbols, Maps, Sets and Advanced Collections, Functional and Declarative Patterns.
- Next: Level 14: Testing & Code Quality: Unit and Integration Testing, Static Analysis and Linting, Designing Testable JavaScript.
In the app each of these ideas is taught and then asked back, and the level ends with a checkpoint and flashcards. See Checkpoints and flashcards.
Frequently asked questions
What does JavaScript Level 13: Runtime & Memory cover?
Call Stack, Heap and Garbage Collection, References and Memory Behaviour, Finding Memory and Runtime Problems: 3 lessons and 9 ideas.
What should I know before this level?
The level before it, Level 12: Advanced Language Patterns, which covers Iterators and Generators, Symbols, Maps, Sets and Advanced Collections, Functional and Declarative Patterns.