01Chapter 1: How JavaScript Allocates and Releases MemoryEvery value your program creates takes up memory. JavaScript hides most of that work from you: you never ask for bytes and never hand them back. The engine still allocates and frees memory, though, and when you write code without a picture of that process you get pages that slow down over hours, Nod6 min read
02Chapter 2: Stack, Heap, and Values vs ReferencesThe garbage collector works on objects, so before you can reason about it you need to know which values are objects and how variables refer to them. This chapter builds that model. It covers what the stack and the heap are, how primitives differ from objects when you assign or pass them, and where t6 min read
03Chapter 3: Reachability: What the Garbage Collector KeepsThis chapter assumes you know JavaScript variables, objects, arrays, and functions. You should also understand closures and scope at a basic level, and be able to run code in a browser console or Node.js. Earlier chapters covered the allocate-use-release lifecycle and how primitives and references d6 min read
04Chapter 4: Reference Counting and Why Cycles Broke ItThis chapter assumes you know JavaScript objects, functions, and closures, and that you understand reachability from the previous chapter: an object stays alive while some chain of references from a root, such as a global or a local variable on the call stack, leads to it. Here you will study an old6 min read
05Chapter 5: Mark-and-Sweep: The Core AlgorithmThis chapter assumes you know JavaScript objects, arrays, and functions, and that you have already met two ideas from earlier chapters. The first is reachability: an object survives if a chain of references from a root leads to it. The second is the cycle problem that broke reference counting. Here 5 min read
06Chapter 6: How Closures Keep Data AliveThis chapter assumes you know how JavaScript closures and lexical scope work, and that you have read the earlier chapters on reachability and mark-and-sweep. Garbage collection roots are the starting points the collector traces from, such as globals and the current call stack. An object survives as 6 min read
07Chapter 7: Common Memory Leaks and How to Fix ThemThis chapter assumes you know how reachability from roots decides what the garbage collector keeps, how mark-and-sweep works, and how closures retain the variables they use. You should also be comfortable with timers, event listeners, and basic DOM manipulation.6 min read
08Chapter 8: Associating Data Without Leaking: WeakMap and WeakSetThis chapter assumes you know the earlier material: reachability from roots, how mark-and-sweep decides what to free, and the leak patterns from the previous chapter, especially unbounded caches. You should also be able to run Node.js from the command line. WeakRef and FinalizationRegistry are cover6 min read
09Chapter 9: Finding Leaks with Heap Snapshots and Allocation ProfilingThis chapter assumes you know what reachability and garbage collection roots are, and that you know the common leak patterns: forgotten timers, listeners, closures, detached DOM nodes, and unbounded caches. You should be able to run Node.js from a terminal and open Chrome DevTools. The goal is a rep8 min read
10Chapter 10: Generational Collection: Young and Old GenerationsThis chapter assumes you already know how mark-and-sweep works: the collector starts from roots, marks every reachable object, and frees the rest. You should also be able to run a script with Node.js from the command line. Here you will see how V8, the engine in Chrome and Node.js, splits the heap b7 min read
11Chapter 11: WeakRef and FinalizationRegistry, and Why to Avoid Relying on ThemThis chapter assumes you know how reachability decides what the collector keeps, how mark-and-sweep works, and how WeakMap and WeakSet hold keys weakly. You should also be able to run scripts in Node.js with command-line flags.6 min read
12Chapter 12: Memory in Node.js: Heap Limits and MonitoringThis chapter assumes you already know how reachability and mark-and-sweep work, how V8 splits the heap into young and old generations, and how to read a heap snapshot in Chrome DevTools. Here those ideas meet a running server. A Node.js process has a fixed heap limit, and its memory includes more th6 min read
13Chapter 13: Shorter Pauses: Incremental, Parallel, and Concurrent GCThe earlier chapters described mark-and-sweep as one complete pass: stop the program, mark everything reachable, then sweep the rest. That description is correct, but a naive version of it causes a practical problem. While the collector runs, your JavaScript does not. On a heap of several hundred me7 min read
14Chapter 14: Writing Code That Allocates LessEarlier chapters covered how V8 finds garbage and how to track down leaks. This chapter covers a separate problem. A program can have no leaks and still spend too much time in garbage collection because it creates short-lived objects faster than it needs to. The rate at which code creates objects is6 min read