Created
September 13, 2014 00:36
-
-
Save misterdjules/0800a480220fe445bd5a to your computer and use it in GitHub Desktop.
Memory leak fix for lab 4 of nodeconf's dtrace + mdb workshop
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
diff --git a/leak2.js b/leak2.js | |
index e4b6a47..7fe4c18 100644 | |
--- a/leak2.js | |
+++ b/leak2.js | |
@@ -7,15 +7,16 @@ result = null; | |
console.log("STARTING"); | |
process.nextTick(function run() { | |
- var script = vm.createScript('setInterval(function() {}, 0);', 'test.js'); | |
+ var script = vm.createScript('var myInterval = setInterval(function() {}, 0); clearInterval(myInterval); ', 'test.js'); | |
var sandbox = { setInterval: setInterval }; | |
- script.runInNewContext(sandbox); | |
+ script.runInThisContext(); | |
total--; | |
if (total) { | |
/* process.nextTick(run); */ | |
- setTimeout(function() { | |
+ var myTimeout = setTimeout(function() { | |
run(); | |
+ clearTimeout(myTimeout); | |
}, 1000); | |
} else { | |
console.log("COMPLETE"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment