01Chapter 1: How JavaScript Allocates and Releases MemoryEvery program uses memory in the same three steps. It allocates the memory it needs, it uses that memory by reading and writing it, and it releases the memory when it is done. Languages such as C make you do the first and last steps yourself with malloc and free. JavaScript does both of them for3 min read
02Chapter 2: Stack, Heap, and Values vs ReferencesThis chapter assumes you know JavaScript variables, objects, arrays, and functions, and that you can run code in a browser console or Node.js. It builds on the allocate-use-release lifecycle from the previous chapter. Here you will see where allocated data lives and what a variable actually holds.3 min read
03Chapter 3: Reachability: What the Garbage Collector KeepsThis chapter assumes you know JavaScript variables, objects, and functions, and that you have met the idea of scope. It builds on the previous chapters, which covered the allocate-use-release lifecycle and the difference between primitives and references.3 min read
04Chapter 4: Reference Counting and Why Cycles Broke ItThis chapter assumes you know JavaScript objects and functions and have read the previous chapter on reachability and garbage collection roots. Reference counting is an older strategy for deciding when memory can be freed. Modern JavaScript engines no longer use it for the JavaScript heap. It is sti3 min read
05Chapter 5: Mark-and-Sweep: The Core AlgorithmThis chapter assumes you know what reachability and garbage collection roots are, and why reference counting fails on cycles. Both were covered in the previous chapters. Here you will see the algorithm that replaced reference counting in every modern JavaScript engine.2 min read
06Chapter 6: How Closures Keep Data AliveThis chapter assumes you know how closures capture variables from an outer scope and how reachability from roots decides what the garbage collector keeps. Closures matter for memory because a function object can be a path from a root to data you thought was gone.2 min read
07Chapter 7: Common Memory Leaks and How to Fix ThemThis chapter assumes you know how reachability from roots decides what the collector keeps, and how closures retain the variables they use. You should also be comfortable with timers, event listeners, and basic DOM APIs.2 min read
08Chapter 8: Associating Data Without Leaking: WeakMap and WeakSetThis chapter assumes you know how reachability decides what the garbage collector keeps, and that you have seen how an unbounded cache can leak. It shows how to attach extra data to objects you don't own without keeping those objects alive.2 min read
09Chapter 9: Finding Leaks with Heap Snapshots and Allocation ProfilingThis chapter assumes you know how reachability decides what the garbage collector keeps, and that you can recognize the common leak patterns from the previous chapter. You should also be able to open Chrome DevTools and run a script with Node.js.3 min read
10Chapter 10: Generational Collection: Young and Old GenerationsThis chapter assumes you know how mark-and-sweep works from the previous chapter and can run Node.js from a terminal. It covers how V8 splits the heap by object age, and why that split makes most collections cheap.3 min read
12Chapter 12: Memory in Node.js: Heap Limits and MonitoringThis chapter assumes you can run scripts with Node.js from a terminal, know what a heap snapshot is from the earlier profiling chapter, and understand that V8 splits the heap into young and old generations.2 min read
13Chapter 13: Shorter Pauses: Incremental, Parallel, and Concurrent GCThis chapter assumes you know how mark-and-sweep works and how V8 splits the heap into a young generation and an old generation. Mark-and-sweep explains what the collector frees. This chapter covers when it does that work, and how V8 keeps the work from freezing your page or server.3 min read
14Chapter 14: Writing Code That Allocates LessThis chapter assumes you know how V8 splits the heap into young and old generations, and that you can take an allocation profile in DevTools. Earlier chapters covered both. The focus here is practical: a few changes that make your code create fewer short-lived objects in places where speed matters.2 min read