javascriptcore-garbage-collector

Explain Bun's JavaScriptCore garbage collector internals for memory management debugging.

95.3k|4.9k|Updated Apr 14, 2021
One-click install
npx skills add https://github.com/oven-sh/bun --skill javascriptcore-garbage-collector
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: javascriptcore-garbage-collector
Source: https://github.com/oven-sh/bun/tree/main/.claude/skills/javascriptcore-garbage-collector
Command: npx skills add https://github.com/oven-sh/bun --skill javascriptcore-garbage-collector

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Bun developers and SREs need a reliable reference to JavaScriptCore's garbage collector (Riptide) as used by Bun. This guide explains GC models, root tracing, and the interactions between JS objects and native state to help diagnose memory-management bugs.

Core Features & Use Cases

  • Understand the non-moving, generational, parallel, mostly-concurrent GC design and how Eden vs Full GC affect performance.
  • Learn how root constraints, WriteBarrier, visitChildren, visitAdditionalChildren, and opaque roots keep objects alive across mutator and GC cycles.
  • Inspect and reason about weak references (JSC::Weak, WeakHandleOwner) and the JS↔native reference patterns (JSRef) used in Zig bindings.
  • Leverage HeapAnalyzer and analyzeHeap hooks to label and trace memory graphs for heap snapshots and debugging memory leaks.

Quick Start

Read this reference to quickly understand Bun's JSC GC behavior when debugging memory leaks and use-after-free scenarios.

Frequently Asked Questions about javascriptcore-garbage-collector

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How does the JavaScriptCore garbage collector work in Bun?

Bun's JavaScriptCore garbage collector uses a non-moving, generational, parallel, mostly-concurrent design. It distinguishes Eden collections from Full GC cycles to manage memory performance across mutator and collector interactions.

How do I debug use-after-free bugs and memory leaks in Bun?

Debug use-after-free bugs and JS object leaks by inspecting root tracing, WriteBarrier, and visitChildren constraints. Leverage HeapAnalyzer and analyzeHeap hooks to label, trace memory graphs, and capture heap snapshots.

When should I use weak references and WriteBarrier in Bun native bindings?

Use weak references like JSC::Weak and WeakHandleOwner for JS↔native reference patterns in Zig bindings. WriteBarrier and visitAdditionalChildren keep objects alive across mutator and GC cycles.

What are IsoSubspace and opaque roots in JavaScriptCore memory management?

IsoSubspace and opaque roots are core JavaScriptCore GC concepts. IsoSubspace manages specific object heap allocations, while opaque roots act as root constraints keeping objects alive during collection cycles.

Why does my Bun application have a JS object leak after a Full GC cycle?

JS object leaks after a Full GC cycle often occur when opaque roots or JSRef patterns in Zig bindings unintentionally keep references alive. Use HeapAnalyzer to trace the memory graph and identify lingering references.