Skip to content

Node.js leaks overview

Node processes often run days or weeks. A few KB leaked per request × millions of requests = outage.

Pattern Runnable example
Global growing array examples/node/01-global-array-leak.js
EventEmitter listeners examples/node/02-event-emitter-leak.js
Closure cache examples/node/03-closure-cache-leak.js
Timers keeping loop alive examples/node/04-timer-handle-leak.js
Unclosed streams examples/node/05-stream-leak.js

Each has a paired *-fixed.js version.

From the project root:

Terminal window
node --expose-gc --inspect examples/node/01-global-array-leak.js

Then open chrome://inspectinspect your Node target → Memory tab.

See examples/node/README.md in the repo for full instructions.

Terminal window
# Watch memory in terminal
node examples/node/01-global-array-leak.js
# With manual GC (compare leak vs fix)
node --expose-gc examples/node/01-global-array-fixed.js