Repository navigation
feat(javascript): the Garbage Collection story, in 2D and 3D - #224
Merged
Merged
Conversation
A nine-beat story of one collection: the collector starts at the roots, marks what references lead to, stops at an object it has already marked, and sweeps what has no mark. Two objects that still reference each other are reclaimed together, because the sweep reads marks, not references. The shared stack-and-heap views now draw a marked object (a MARKED tag and a heavier outline, only while a collection is in progress) and keep the two references of a mutual pair apart. The section's old simulation, which ignored its own editor and had no roots, is removed. Also: the story's program as a Playground example, two quiz questions on cycles, and a passage on roots, cycles and reference counting in the research report. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The story
Question: how does the collector decide what to free, and why can two objects that reference each other not keep each other alive?
A short program builds two parent-and-child pairs that point at each other, then sets one variable to
null. Nine beats follow one collection:draft = null: the stack reference goes; the two objects still point at each other.pageand marks that object.Spec:
docs/stories/javascript/garbage-collection.md, approved 2026-10-13 with its eight decisions recorded.What changes
garbageCollectionStory.ts). The tests prove the key claim from the data: the sweep reclaims exactly the objects no path from a root reaches, and each reclaimed object still had a reference pointing at it.MARKEDtag and a heavier outline in the object's own colour. It is drawn only while a collection is in progress, so Playground traces look as before.garbage-collection-story.Relation to the Playground
A trace of the same program reproduces beats 1 and 2, and a test confirms the two objects a trace marks unreachable are exactly the two the story's sweep reclaims. Beats 3 to 8 are authored: a run cannot observe marking or a sweep.
Checks
npx tsc -b,npm run lintandnpm run buildpass; three.js is not in the entry graph.npm run test:runpassed in full once on this branch (1,434 tests in 104 files). Later full runs on the same machine, which was busy with unrelated builds, had timeouts inPlaygroundApp.exercises,Sidebar,HeaderandProgresstests. Each of those files passes when run by itself. CI is the cleaner measure.Checked in the browser: all nine beats in 2D with the right tags on each; beats 6 and 8 in 3D; a fresh 3D load stepped through every beat and switched back to 2D with no console errors; the link from the Stack ↔ Heap story.
Not checked in a browser
Reduced motion, the no-WebGL fallback and Hold view for this story; the Stack ↔ Heap story and Playground traces after the shared-view changes (covered by tests).
🤖 Generated with Claude Code