Created
October 26, 2012 22:24
-
-
Save micahcatlin/3961918 to your computer and use it in GitHub Desktop.
Fragment for generating collectable garbage
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
| 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