---
title: "Chapter 8. Garbage, Profiles, and the Limits of JIT"
url: "https://www.mikefluff.com/en/read/from-closures-to-autonomous-systems/ch08"
locale: "en"
author: "Mikhail Savchenko (Mike Fluff)"
updated: "2026-11-18T12:24:57.879Z"
book: "https://www.mikefluff.com/en/books/from-closures-to-autonomous-systems"
access: "lead-in"
purchase: "https://www.mikefluff.com/en/books/from-closures-to-autonomous-systems"
alternates:
  - locale: "ru"
    url: "https://www.mikefluff.com/ru/read/from-closures-to-autonomous-systems/ch08"
    markdown: "https://www.mikefluff.com/ru/read/from-closures-to-autonomous-systems/ch08.md"
  - locale: "en"
    url: "https://www.mikefluff.com/en/read/from-closures-to-autonomous-systems/ch08"
    markdown: "https://www.mikefluff.com/en/read/from-closures-to-autonomous-systems/ch08.md"
  - locale: "pt"
    url: "https://www.mikefluff.com/pt/read/from-closures-to-autonomous-systems/ch08"
    markdown: "https://www.mikefluff.com/pt/read/from-closures-to-autonomous-systems/ch08.md"
---

# Chapter 8. Garbage, Profiles, and the Limits of JIT

*[JavaScript: From Closures to Autonomous Systems](https://www.mikefluff.com/en/books/from-closures-to-autonomous-systems)*

In the first chapter I mentioned in passing that in JavaScript the programmer never decides when an object dies; from day one the garbage collector does that. This handover of responsibility was invented long before JavaScript: in 1960 John McCarthy described Lisp, in which memory for unneeded data was freed by itself, and ever since languages have split into those where the programmer looks after memory and those where the machine does. JavaScript was born into the second camp and has never let the programmer free an object by hand. An object lives as long as it can be reached through references and dies when it no longer can, and who notices this and when is none of the programmer’s business.

The simplest garbage collector stops the program, walks all the objects that can be reached and throws away the rest. It works reliably but slowly, and the bigger the memory, the longer the program stands still. In the early eighties, by the estimates of the time, collection in Smalltalk took twenty to thirty percent of the virtual machine’s work. In 1984 David Ungar, who two years later would invent Self, built a collector for Berkeley Smalltalk that spent a few percent on collection and caused no noticeable pauses.

Ungar noticed what would later be called the generational hypothesis: most objects die young. A program creates a temporary object, uses it for a couple of microseconds and drops it, and only a small fraction of objects live to something like maturity. So it pays to house young objects separately and collect them often. At collection time there are few live objects; they are copied elsewhere, and all the remaining space is declared free wholesale, without looking at what lay there. The cost of such a collection depends only on the number of survivors, however many objects died, and if almost all of them died, collection costs almost nothing.

---

The rest of this chapter is free on the site once the reader confirms an email address: https://www.mikefluff.com/en/read/from-closures-to-autonomous-systems/ch08
