Surely you're just dumping the memory usage before you remove the timer?
var btnPin = BTN; var ledPin = LED1; var ledTimer = null; digitalWrite(ledPin, 0); var btnWatcher = setWatch(function () { console.log("--" + process.memory().usage); // <------------------------------ if (ledTimer) { clearTimeout(ledTimer); ledTimer = null; } digitalWrite(ledPin, 1); console.log("before: " + ledTimer); ledTimer = setTimeout(function () { digitalWrite(ledPin, 0); ledTimer = null; }, 4000); console.log("after: " + ledTimer); }, btnPin, {repeat: true, edge: "rising", debounce: 70}); --79 before: null after: 2 --106 before: null after: 4 --107 before: null after: 6 --107 before: null after: 8
Try this:
var btnPin = BTN; var ledPin = LED1; var ledTimer = null; digitalWrite(ledPin, 0); var btnWatcher = setWatch(function () { if (ledTimer) { clearTimeout(ledTimer); ledTimer = null; } console.log("--" + process.memory().usage); // <------------------------------ digitalWrite(ledPin, 1); console.log("before: " + ledTimer); ledTimer = setTimeout(function () { digitalWrite(ledPin, 0); ledTimer = null; }, 4000); console.log("after: " + ledTimer); }, btnPin, {repeat: true, edge: "rising", debounce: 70}); --79 before: null after: 2 --80 before: null after: 4 --80 before: null after: 6 --80 before: null after: 8 --80 before: null after: 10
@Gordon started
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Surely you're just dumping the memory usage before you remove the timer?
Try this: