memory storage and widget

Hi all,

I am trying to convert an app to widget. to limit web request I was storing the result in "properties".

but with widget i got :

Error: Out Of Memory Error
Details: Failed invoking <symbol>

is there a difference in meory handling from app and widget ?

what is the memory limit ?

thanks

  • There is a difference in the limits for app and widget, and it is different for each device. You can see the limits on simulator, either bottom left of main view, or then memory info page

  • Limits also vary by device and even the music version of a device vs the non-music version.

  • so what's the best way to keep data between "execution".

    I was thinking of using the same code for background task, but if I understand correctly there will also be a limit ?

    i was retreiving a JSON from web, I know I don't need all the data, do i need to "clean/keep" only what's needed ?

  • Ok, a few things here.  The background doesn't have as much memory as the full widget.  32k is common.  Then, there are glace view where agian its commonly 32k (28k after the VM grabs it's piece), where when a glance loads, it's the code for that as well as the background.  In full screen, it's the code for that, glance mode and background.  Full screen mode memory is what you see in the sim unless you're looking at the glance view.

    What I do is in onBackgroundData, I store the data in Application.Storage or the object store.  My makeWebRequest runs in the background.  When passing data from the background using Background.exit(), you are limited to 8k.  It's really up to you if you reduce what's passed back

  • thanks for clarification, here is the code I use, from your explaination I was thinking that I was using Application.Storage like you said, and was ok with limit. the return size from the JSON seems to be around 16k, is it OK ?

    function setLastData(data) {
        var myapp = App.getApp();
    
        if (Toybox.Application has :Storage && Toybox.Application.Storage has :setValue) {            
                myapp.Storage.setValue("lastdata",data);
        } else {
                myapp.setProperty("lastdata",data);
        }
    }
    

  • Where setLastData() is called from onBackgroundData if you are doing the comm in the background..

    You also want to load what's saved when the app starts.

  • here is the "load part", asfor now, i didn't use background service, I only use "real time" for testing

     :

    /* handle last data date with SDK version */
    function getLastData() {
        var myapp = App.getApp();
        var data = null;
        if (Toybox.Application has :Storage && Toybox.Application.Storage has :setValue) {
                data = myapp.Storage.getValue("lastdata");
        } else {
                data = myapp.getProperty("lastdata");
        }

        return data;
    }

  • One thing, and maybe it's just me, but I avoid using "has" in different places.  It can be an expensive operation.

    What I do is set a boolean using "has" in initialize() and after that, just check the boolean.