-
@Gordon and @halemmerich have given some pointers following comment #63 in the POC-thread. Information on how to declare functions with
let
to have them cleared on app exit is in comment #48.It basically boils down to:
- Wrap all your app code inside outer curly brackets:
{ all app code inside }
- Initialize variables with
let
orconst
, to utilize garbage collection. - Define functions by:
let myfun = function() { ... }
instead offunction myfun() { ... }
, also to utilize garbage collection. - Add to Bangle.setUI:
remove : someRemoveFunction
- EDIT as per @halemmerich's post below: Clear timeouts/invervals etc in
someRemoveFunction
in the step above. - Use
Bangle.showLauncher()
,Bangle.showClock()
orBangle.load()
instead ofload()
.
For now it's generally best to only implement fast switching between clocks and launchers, and not for launching other apps or switching between them.
There're also instructions going into the hardware reference here following line 5171.
Examples where it's implemented: Slope clock, Desktop Launcher.
EDIT: Using the RAM Widget have helped me during development. @Gordon has also suggested entering
process.memory().usage
into the console field of the Web IDE to get precise measurements. See @halemmerich tips below as well. - Wrap all your app code inside outer curly brackets:
-
Edit: Removed duplication with @Ganblejs earlier post.
- Check for any watches, timeouts, intervals that might survive the removal of the app and clear them in
remove
. - If code running in timeouts or intervals needs access to variables you might need to move them out of the block into the global scope. Those must then explicitly be deleted during
remove
.
I use the following uploaded to RAM to do a smoke test for memory leaks:
let app = "launch.app.js"; print("Initally load app", process.memory().free); Bangle.load(app) setInterval(()=>{ print("Reload app with free", process.memory().free); Bangle.load(app); },1000);
This code loads the app over and over. It usually settles in after 1 or 2 iterations and does not change a lot after that with most apps. This will not cover all cases, but it should give you a start. As usual, do changes piece by piece and test between steps.
- Check for any watches, timeouts, intervals that might survive the removal of the app and clear them in
yes.
Bummer, I hoped it was easier. Could you guys help me to tidy up the watchface somehow?
It might look as I'm a programmer, but most I do is copy&paste (like a senior programmer - but without the background knowledge :) )