mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 18:38:55 +00:00
Fix memory leak when printing any error's source code. (#12831)
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
This commit is contained in:
23
test/js/bun/util/inspect-error-leak.test.js
Normal file
23
test/js/bun/util/inspect-error-leak.test.js
Normal file
@@ -0,0 +1,23 @@
|
||||
import { test, expect } from "bun:test";
|
||||
|
||||
const perBatch = 2000;
|
||||
const repeat = 50;
|
||||
test("Printing errors does not leak", () => {
|
||||
function batch() {
|
||||
for (let i = 0; i < perBatch; i++) {
|
||||
Bun.inspect(new Error("leak"));
|
||||
}
|
||||
Bun.gc(true);
|
||||
}
|
||||
|
||||
batch();
|
||||
const baseline = Math.floor(process.memoryUsage.rss() / 1024);
|
||||
for (let i = 0; i < repeat; i++) {
|
||||
batch();
|
||||
}
|
||||
|
||||
const after = Math.floor(process.memoryUsage.rss() / 1024);
|
||||
const diff = ((after - baseline) / 1024) | 0;
|
||||
console.log(`RSS increased by ${diff} MB`);
|
||||
expect(diff, `RSS grew by ${diff} MB after ${perBatch * repeat} iterations`).toBeLessThan(10);
|
||||
}, 10_000);
|
||||
Reference in New Issue
Block a user