Node --inspect
Start inspector
Section titled “Start inspector”node --inspect examples/node/03-closure-cache-leak.js# or break on first line:node --inspect-brk examples/node/03-closure-cache-leak.jsOutput:
Debugger listening on ws://127.0.0.1:9229/...Attach
Section titled “Attach”- Chrome →
chrome://inspect - Configure → ensure
localhost:9229listed - inspect link under Remote Target
Same Memory / Performance tabs as browser debugging.
With garbage collection
Section titled “With garbage collection”node --expose-gc --inspect examples/node/01-global-array-fixed.jsIn console: gc() (when exposed) or use Memory tab trash icon.
v8.writeHeapSnapshot
Section titled “v8.writeHeapSnapshot”import v8 from 'node:v8';
setInterval(() => { const path = v8.writeHeapSnapshot(); console.log('snapshot', path);}, 60_000);Ship snapshots from staging — analyze locally in DevTools.
Case study tie-in
Section titled “Case study tie-in”| Script | Expected retainer |
|---|---|
01-global-array-leak.js |
global → store array |
02-event-emitter-leak.js |
EventEmitter listeners array |
03-closure-cache-leak.js |
jobs → closure contexts |