bun
bun copied to clipboard
Blob allocations cause excessive memory, and GC does not release all memory / Windows 10 / `Blob,Uint8Array,ArrayBuffer`
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?
- 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]);
}
- Allocate 14 blobs using this function (
Array.from({length: 14}, create1GBData)). - Observe memory usage (e.g., via Task Manager).
- Force garbage collection (manual GC).
- 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.
Bun
Node
@mizulu Just curious: does this repro on the latest version of Bun for you?
@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.
@mizulu Roger that. Thanks!