Small callbacks retain an entire large array via closure.
Closure entries — check retained sizeClosure count increasesArray and Object held inside closure contextEach callback only uses huge.length, but JavaScript closures capture the entire lexical scope — including the 40,000-element array.
Callbacks are stored in an array. Each one closes over a large huge array from its creation scope, retaining it even though only .length is read.
// Fix: extract only what you need before creating the callback const len = huge.length; const cb = () => len; // Or clear the callbacks array when done callbacks.length = 0;