espruino / Espruino

The Espruino JavaScript interpreter - Official Repo
http://www.espruino.com/
Other
2.77k stars 745 forks source link

[BangleJS] Leaking memory / garbage while calling Bangle.beep() #2034

Closed peeweek closed 3 years ago

peeweek commented 3 years ago

Hello, I'm currently on 2v09 and I figured out while working that my bangle memory was filling up slowly every time I was calling a Bangle.beep(). I have been using it naively so far when making interactions and I stumbled upon out of mem issues after a while. After debugging I ended up figuring out that every beep was consuming roughly 1 block of memory each call.

Is there a way for me to prevent that? Am I using it wrong?

I've osolated part of my code and made a sample logger with the free memory :

class beep {
  static select () {
    Bangle.beep(20,880).then(()=>Bangle.beep(50,1200));
  }
  static move() {
    Bangle.beep(20,440);
  }
  static deny() {
    Bangle.beep(20,440).then(()=>Bangle.beep(50,220));
  }
}

function logMem() {
  print(process.memory().free);
}

function onB1() {
  beep.select();
  logMem();
}
function onB2() {
  beep.move();
  logMem();
}
function onB3() {
  beep.deny();
  logMem();
}

// Handle Button Press
setWatch(onB1, BTN1, true);
setWatch(onB2, BTN2, true);
setWatch(onB3, BTN3, true);

Screenshot from 2021-07-30 16-44-44

gfwilliams commented 3 years ago

This sounds bad - thanks for spotting it! I'll look into it first thing Monday

gfwilliams commented 3 years ago

Looks like this was already fixed as part of https://github.com/espruino/Espruino/commit/221792142d8c6bf18a61d19b778e13a575a46e0f - it'll be in 2v10 (or cutting edge builds)