---
title: "Understanding Garbage Collection in JavaScriptCore From Scratch"
description: "JavaScriptCore's garbage collector is non-compacting, generational and mostly concurrent, with heavy use of lock-free programming."
url: "https://swe.quest/articles/understanding-garbage-collection-in-javascriptcore-from-scratch-6bc19cc2aad39444"
canonical: "https://webkit.org/blog/12967/understanding-gc-in-jsc-from-scratch/"
source: "WebKit"
published: "2022-07-29"
difficulty: "hard"
kind: "Deep dive"
reading_minutes: 52
tags: ["memory-management","runtimes","javascript","concurrency"]
---

# Understanding Garbage Collection in JavaScriptCore From Scratch

A post on [WebKit](https://swe.quest/sources/webkit.md), published 2022-07-29, 52 min read, Deep dive. Original: [https://webkit.org/blog/12967/understanding-gc-in-jsc-from-scratch/](https://webkit.org/blog/12967/understanding-gc-in-jsc-from-scratch/)

## Summary

JavaScriptCore's garbage collector is non-compacting, generational and mostly concurrent, with heavy use of lock-free programming. The explanation starts from a naive stop-the-world generational collector and adds pieces one at a time until it reaches JSC's real design. Along the way it covers BlockDirectory-based allocators (CompleteSubspace, PreciseAllocation, IsoSubspace), why per-object metadata is split between an inlined cellState and outlined isNew/isMarked bitvectors, and how write barriers and remembered sets keep marking correct. For incremental and concurrent collection it adds remembered-set scheduling and Space-Time Scheduler mitigations, which address up to 5x memory blowup.

Written by swe.quest, not by the author.

**Difficulty:** Hard: written for specialists in the field

## Topics

- [Memory management](https://swe.quest/tags/memory-management.md) (Compilers & runtimes)
- [Runtimes & VMs](https://swe.quest/tags/runtimes.md) (Compilers & runtimes)
- [JavaScript](https://swe.quest/tags/javascript.md) (Languages)
- [Concurrency](https://swe.quest/tags/concurrency.md) (Compilers & runtimes)

## Prerequisites

- garbage collection basics ([easy posts on Memory management](https://swe.quest/tags/memory-management.md?difficulty=easy))
- generational GC ([easy posts on Memory management](https://swe.quest/tags/memory-management.md?difficulty=easy))
- memory allocators ([easy posts on Memory management](https://swe.quest/tags/memory-management.md?difficulty=easy))
- lock-free programming ([easy posts on Concurrency](https://swe.quest/tags/concurrency.md?difficulty=easy))

## Keywords

JavaScriptCore, WebKit, BlockDirectory, CompleteSubspace, PreciseAllocation, IsoSubspace, libpas, write barrier

## Related posts

- [Introducing the JetStream 3 Benchmark Suite](https://swe.quest/articles/introducing-the-jetstream-3-benchmark-suite-df1c85fb12e2a75d.md): WebKit · 2026-03-31 · Hard · 21 min read · Runtimes & VMs, WebAssembly, Compilers, Memory management, Performance engineering
  JetStream 3 replaces JetStream 2's separate Wasm Startup/Runtime scores with the JavaScript-style first-iteration, worst-case and average-case scoring.
- [Size-Specialized Memory Allocation](https://swe.quest/articles/size-specialized-memory-allocation-cb92a01eba7d925f.md): The Go Blog · 2026-09-16 · Hard · 7 min read · Memory management, Go, Runtimes & VMs, Performance engineering
  Go 1.27 adds size-specialized variants of the runtime's mallocgc for allocations of 80 bytes or fewer, one per span class (size class plus pointer/no-pointer), making these allocations 20-30% faster and allocation-heavy programs up to 1% faster.
- [Oilpan library · V8](https://swe.quest/articles/oilpan-library-v8-a23ba3c3b59aeb1f.md): V8 · 2021-11-10 · Hard · 5 min read · Memory management, Runtimes & VMs, C & C++, Browsers
  Oilpan, the trace-based C++ garbage collector originally built for Blink, has been extracted into a library hosted in V8 since v9.4 (enabled in Chromium M94) under the cppgc namespace.
- [Adventures in Garbage Collection: Improving GC Performance in our Massive Monolith](https://swe.quest/articles/adventures-in-garbage-collection-improving-gc-performance-in-our-massive-7c8cc3e83e915743.md): Shopify Engineering · 2023-04-06 · Hard · 13 min read · Memory management, Ruby, Performance engineering, Runtimes & VMs
  Shopify cut Ruby garbage-collection tail latency in its monolith by finding why major GCs were triggered, via GC.latest\_gc\_info(:major\_by), and removing each cause in turn.
- [Bun 1.4](https://swe.quest/articles/bun-1-4-fea28913dacb5d89.md): Bun · 2026-08-20 · Medium · 217 min read · Runtimes & VMs, JavaScript, Performance engineering, Memory management, Rust
  Bun 1.4 adds 1,517 newly passing Node.js test-suite tests, fixes over 2,900 issues, and rewrites Bun from Zig to Rust.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
