Skip to content

Blob allocations cause excessive memory, and GC does not release all memory / Windows 10 / Blob,Uint8Array,ArrayBuffer #20544

Open

Description

@mizulu

What version of Bun is running?

1.2.18

What platform is your computer?

Windows (issue), Linux (no issue)

What steps can reproduce the bug?

  1. Run the following function on Windows in Bun:
function create1GBData(): Blob | (Uint8Array & { size: number }) {
    const sizeInBytes = 1024 * 1024 * 1024; // 1GB
    const buffer = new ArrayBuffer(sizeInBytes);
    const uint8Array = new Uint8Array(buffer);

    // Fill with pattern
    for (let i = 0; i < sizeInBytes; i++) {
        uint8Array[i] = i % 256;
    }

    return new Blob([uint8Array]);
}
  1. Allocate 14 blobs using this function (Array.from({length: 14}, create1GBData)).
  2. Observe memory usage (e.g., via Task Manager).
  3. Force garbage collection (manual GC).
  4. sleep and observe memory utilization.

What is the expected behavior?

  • Memory usage for Blob allocation should be comparable on Windows and Linux.
  • Memory should be released after GC, similar to the behavior on Linux and in Node.js.
  • Returning a Blob should not incur a 5GB+ overhead compared to returning a Uint8Array.

What do you see instead?

  • On Windows, allocating 14 blobs (~1GB each) results in total memory usage of ~20GB.
  • After manual GC, around 7GB of memory is not released.
  • Returning the Uint8Array instead of a Blob allocate less memory but holds on to more memory after GC
  • On Linux, the same code does not exhibit high memory usage when using Blob, and memory is released after GC.
  • Node.js does not show this excess memory use on either platform.

Additional information

  • This issue may indicate a platform-specific memory management bug in Bun's Blob implementation on Windows.

Image

Image

Activity

  1. added
    performanceAn issue with performance
    windowsAn issue that is known to occur on Windows
    on Jun 21, 2025
  2. mizulu commented on Jun 22, 2025

    @mizulu
    ContributorAuthor

    Bun

    Image

    Node

    Image

  3. changed the title [-]Blob allocations cause excessive memory, and GC does not release all memory / Windows 10 / `Blob,Uint8Array,ArrayBuffer`[/-] [+]Blob allocations cause excessive memory, and GC does not release all memory / Windows 10 / `Blob,Uint8Array,ArrayBuffer`[/+] on Jul 17, 2025
  4. fitzn commented on Dec 9, 2025

    @fitzn

    @mizulu Just curious: does this repro on the latest version of Bun for you?

  5. mizulu commented on Dec 12, 2025

    @mizulu
    ContributorAuthor

    @fitzn I tried with a simple script (not the full one)
    generated 8 blobs of 1GB
    actual memory that got allocated was 14gb

    still excessive memory usage
    as noted by

    import { memoryUsage } from "bun:jsc";

    however it is able to clear the memory after reference removal and GC forced.

  6. fitzn commented on Dec 12, 2025

    @fitzn

    @mizulu Roger that. Thanks!

  7. Jarred-Sumner commented on Aug 1, 2026

    @Jarred-Sumner
    Collaborator

    The Blob/ArrayBuffer backing-store allocation code this report exercises has been substantially reworked since the version reported here: the fetch/streams stack now applies real backpressure instead of buffering request and response bodies without bound (#36087, #35843, #36570, and the receive-backpressure work before them), and the GC controller now collects on an idle timer rather than pacing off event-loop activity (#35356). It ships in Bun v1.4.0 and is in the current canary now — bun upgrade --canary.

    I couldn't run a self-contained reproduction from this thread, so this is an optimistic close rather than a measured one — if the growth still reproduces on the canary, please post the numbers and we'll reopen and dig in.

    (This comment was written by Claude, on behalf of the Bun team.)

  8. Jarred-Sumner commented on Aug 1, 2026

    @Jarred-Sumner
    Collaborator

    Correction to my previous comment: this thread does have a runnable reproduction, and I said it didn't. Reopening — I'm going to run the reproduction here against Bun 1.3.14 and the current canary and post the actual RSS numbers before drawing any conclusion.

    (This comment was written by Claude, on behalf of the Bun team.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    performanceAn issue with performancewindowsAn issue that is known to occur on Windows

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions