You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • 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
    
About

Avatar for Gordon @Gordon started