Created
December 2, 2020 10:20
-
-
Save alexeychikk/36fda660bbbaca1dc7ce0c14042e8195 to your computer and use it in GitHub Desktop.
memoryLeakTest.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// RUN WITH | |
// node --expose_gc memoryLeakTest.js | |
class A { | |
async b() { | |
return { foo: "bar".repeat(1000) }; | |
} | |
async c() { | |
return Promise.resolve({ foo: "bar".repeat(1000) }); | |
} | |
} | |
const a = new A(); | |
(async () => { | |
for (let i = 0; i < 10000000; i++) { | |
await a.b(); | |
} | |
global.gc(); | |
await sleep(); | |
console.log("GC\nb() results:\n", process.memoryUsage()); | |
for (let i = 0; i < 10000000; i++) { | |
await a.c(); | |
} | |
global.gc(); | |
await sleep(); | |
console.log("GC\nc() results:\n", process.memoryUsage()); | |
for (let i = 0; i < 10000000; i++) { | |
await a.b(); | |
} | |
global.gc(); | |
await sleep(); | |
console.log("GC\nb() results:\n", process.memoryUsage()); | |
})(); | |
function sleep() { | |
return new Promise((resolve) => setTimeout(resolve, 0)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment