Last active
August 27, 2024 09:17
-
-
Save kt3k/b705f858331f061c538033717cedc884 to your computer and use it in GitHub Desktop.
This file contains 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
let counter = 0; | |
const registry = new FinalizationRegistry(() => { | |
console.log(`Array gets garbage collected at ${counter}`); | |
}); | |
(function allocateMemory() { | |
// Allocate 50000 functions — a lot of memory! | |
registry.register(Array.from({ length: 50000 }, () => () => {})); | |
if (counter > 1000) { | |
console.log("Main job ends"); | |
return; | |
} | |
counter++; | |
// Use setTimeout to make each allocateMemory a different job | |
setTimeout(allocateMemory, 10); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment