You are reading a single comment by @Hank and its replies. Click here to read the full conversation.
  • You mean for hworldclock itself after the merge?

    yes.

    Actually works only once, it seems some more cleanup is needed

    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 :) )

  • @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:

    1. Wrap all your app code inside outer curly brackets: { all app code inside }
    2. Initialize variables with let or const, to utilize garbage collection.
    3. Define functions by: let myfun = function() { ... } instead of function myfun() { ... }, also to utilize garbage collection.
    4. Add to Bangle.setUI: remove : someRemoveFunction
    5. EDIT as per @halemmerich's post below: Clear timeouts/invervals etc in someRemoveFunction in the step above.
    6. Use Bangle.showLauncher(), Bangle.showClock() or Bangle.load() instead of load().

    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.

  • 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.

About

Avatar for Hank @Hank started