Skip to content

Instantly share code, notes, and snippets.

@mcollina
Last active March 21, 2022 15:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcollina/1a56c2a7fc1c8da7f74729535b4091bf to your computer and use it in GitHub Desktop.
Save mcollina/1a56c2a7fc1c8da7f74729535b4091bf to your computer and use it in GitHub Desktop.
Error keep things from collecting
// Taken from https://twitter.com/robpalmer2/status/1505881530379419652?s=20&t=rNQb26Rwq0fddQHbhalpbw
function test() {
const lotsOfMemory = new Uint8Array(1000 * 1000 * 100);
function retains() { lotsOfMemory }
const someNumber = Math.random();
setInterval(() => {
console.log(someNumber);
}, 1000);
}
test(); // See 100MB forever in heap inspector
let error;
function test() {
const data = new Array(1000000).fill(0);
return () => {
error = new Error();
data.push(0);
}
}
test()();
setTimeout(() => {
console.log(error.stack);
}, 10000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment