Skip to content

Instantly share code, notes, and snippets.

@micahcatlin
Created October 26, 2012 22:24
Show Gist options
  • Select an option

  • Save micahcatlin/3961918 to your computer and use it in GitHub Desktop.

Select an option

Save micahcatlin/3961918 to your computer and use it in GitHub Desktop.
Fragment for generating collectable garbage
var makeSimulatedGameLoop = function(n) {
/* Pre-initialize an array with distinct simple objects */
var g = new Array(1000*n);
var count = 0;
for (i=0; i< g.length; i++) {
g[i] = {count: count++};
}
var _work = function() {
var i;
for (i=0; i < g.length; i++) {
/* For every game variable, double it's count property. */
/* Implicitly create a new object, garbaging the old one. */
g[i] = { count: g[i].count * 2 };
};
};
return _work;
};
computeNextGameStateAndPaint = makeSimulatedGameLoop(20); // Try 2, 20, 200
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment