I haven't looked into your code I'm afraid, but when memory isn't freed in menus, I find it's often because of something like this:
function menuA() {
console.log(process.memory().usage);
E.showMenu({
one : menuB
})
}
function menuB() {
console.log(process.memory().usage);
E.showMenu({
two : menuA
})
}
menuA();
The problem here is that E.showMenu calls functions with menu as an argument. Even though the argument isn't used in either menuA/menuB it's still there (in case some code in the function used arguments) so you're stuck with this chain of references.
If you use () => menuA() instead of just menuA then that ditches the argument, and memory isn't leaked
function menuA() {
console.log(process.memory().usage);
E.showMenu({
one : () => menuB()
})
}
function menuB() {
console.log(process.memory().usage);
E.showMenu({
two : () => menuA()
})
}
menuA();
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.
I haven't looked into your code I'm afraid, but when memory isn't freed in menus, I find it's often because of something like this:
The problem here is that
E.showMenu
calls functions withmenu
as an argument. Even though the argument isn't used in either menuA/menuB it's still there (in case some code in the function usedarguments
) so you're stuck with this chain of references.If you use
() => menuA()
instead of justmenuA
then that ditches the argument, and memory isn't leaked