Node.js leaks overview
Node processes often run days or weeks. A few KB leaked per request × millions of requests = outage.
Server leak patterns in this course
Section titled “Server leak patterns in this course”| 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.
How to run examples
Section titled “How to run examples”From the project root:
node --expose-gc --inspect examples/node/01-global-array-leak.jsThen open chrome://inspect → inspect your Node target → Memory tab.
See examples/node/README.md in the repo for full instructions.
# Watch memory in terminalnode examples/node/01-global-array-leak.js
# With manual GC (compare leak vs fix)node --expose-gc examples/node/01-global-array-fixed.js