mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
Add v8 heap snapshot guide
This commit is contained in:
26
docs/guides/runtime/heap-snapshot.md
Normal file
26
docs/guides/runtime/heap-snapshot.md
Normal file
@@ -0,0 +1,26 @@
|
||||
---
|
||||
name: Track memory usage using V8 heap snapshots
|
||||
---
|
||||
|
||||
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.
|
||||
|
||||
```ts#snapshot.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
|
||||
|
||||
{% image src="/images/chrome-devtools-memory.png" alt="Chrome DevTools Memory Tab" width="100%" /%}
|
||||
Reference in New Issue
Block a user