Skip to content

Instantly share code, notes, and snippets.

View rus0000's full-sized avatar

Ruslan Iusupov rus0000

View GitHub Profile
@rus0000
rus0000 / leak-example.ts
Created November 1, 2018 18:26 — forked from Istar-Eldritch/leak-example.ts
Trampolining "memory leak" on ES6 recursive promise resolve chain.
const promiseYoullWork = () => Promise.resolve();
async function job(todo: number, iterations: number = 0): Promise<number> {
// Print memory consumption of the process every 10k iterations
if (iterations % 10000 === 0) {
const memUsage = process.memoryUsage();
const mem = (memUsage.heapTotal / 1024 / 1024);
console.log(`i: ${iterations / 1000}k`, `mem: ${Math.round(mem * 100) / 100} Mb`);
}
if (iterations === todo) {