Node.js EventEmitter memory leak when attaching dynamic listeners in loops
DomainNODEJS
ImpactHigh
Error Signature
MaxListenersExceededWarning: Possible EventEmitter memory leak detected
Attaching event listeners inside loops or dynamic component mounts without cleanup causes Node.js to emit MaxListenersExceededWarning and leak memory. The default limit of 10 listeners per event is silently exceeded.
Root Cause
EventEmitter maintains an internal array of listeners per event name. Each call to .on() or .addListener() appends without deduplication. In loops, async iterators, or React useEffect hooks without cleanup, the array grows unbounded. The default maxListeners is 10 and only warns at 11+; it does not throw, so leaks often go unnoticed in production until memory pressure becomes critical.
Validation
[object Object]
Ecosystem: nodejs
License: CC-BY-4.0
Last updated: May 21, 2026