Skip to content

Instantly share code, notes, and snippets.

@cprcrack
Created June 30, 2014 10:37
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 cprcrack/b592e0d8905c5706effd to your computer and use it in GitHub Desktop.
Save cprcrack/b592e0d8905c5706effd to your computer and use it in GitHub Desktop.
Closures memory leak test
var functionRefs = [];
function callMeBack(callback)
{
setTimeout(callback, 100);
functionRefs.push(callback); // If I comment this, the leak dissapears!!! -> But I can't do this, it's handled by Parse
}
function start()
{
var bigArray = []; // 10 MB
for (var i = 0; i < 10 * 1024 * 1024; i++)
{
bigArray[i] = 0;
}
callMeBack(function ()
{
console.log(bigArray.length);
setTimeout(start, 100);
//bigArray = null; // If I uncomment this, the leak dissapears!!! -> And this is something I can do :)
});
}
start();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment