Skip to main content
Bun implements V8’s heap snapshot API, which allows you to create snapshots of the heap at runtime. This helps debug memory leaks in your JavaScript/TypeScript application.
https://mintcdn.com/bun-1dd33a4e-claude-spawn-pty-support/QoBJ_wda4qs1OZ4-/icons/typescript.svg?fit=max&auto=format&n=QoBJ_wda4qs1OZ4-&q=85&s=7e69f1d0981fed9617c1ae7f85ad9758snapshot.ts
import v8 from "node:v8";

// Creates a heap snapshot file with an auto-generated name
const snapshotPath = v8.writeHeapSnapshot();
console.log(`Heap snapshot written to: ${snapshotPath}`);

Inspect memory in Chrome DevTools

To view V8 heap snapshots in Chrome DevTools:
  1. Open Chrome DevTools (F12 or right-click and select “Inspect”)
  2. Go to the “Memory” tab
  3. Click the “Load” button (folder icon)
  4. Select your .heapsnapshot file
Chrome DevTools Memory Tab