Jarred Sumner on X: "Here's a 1 GB memory reduction for very long Claude Code sessions Before: `() => controller.abort()` Fix: `controller.abort.bind(controller)`"

Conversation

Here's a 1 GB memory reduction for very long Claude Code sessions Before: `() => controller.abort()` Fix: `controller.abort.bind(controller)`
    if (signal) signal.addEventListener('abort', () => controller.abort());

    const timeout = setTimeout(() => controller.abort(), ms);
    // Avoid creating a closure over `this`, `init`, or `options` to prevent memory leaks.
    // An arrow function like `() => controller.abort()` captures the surrounding scope,
    // which includes the request body and other large objects. When the user passes a
    // long-lived AbortSignal, the listener prevents those objects from being GC'd for
    // the lifetime of the signal. Using `.bind()` only retains a reference to the
    // controller itself.
    const abort = controller.abort.bind(controller);
    if (signal) signal.addEventListener('abort', abort, { once: true });

    const timeout = setTimeout(abort, ms);
5:01 AM · Feb 1, 2026
1.5M
Views