background and memory

1. I can see a different size memory for background for different devices (f7 65536, f6 32768...). I can't find table for all devices, so is 32768 the minium for all of them (CIQ >=2.4)?

2. How to find out about objects in background. I can see  used :18920 free:9720 total:28640 but want to now what is in the 18920. I need about 11kB so have to free something.

  • 1. I can see a different size memory for background for different devices (f7 65536, f6 32768...). I can't find table for all devices, so is 32768 the minium for all of them (CIQ >=2.4)?

    Yes, they're all either 32768 or 65536.

  • You can find the max per devices if you look in the devices files, but understand when you see 32768, there is actually 4k less than that available you your app, as the VM takes the 4k.  

    The 18920 is your code and data, and things are included like AppBase and globals The 28640 is what your app can use (that 32k-4k I mentioned).  As far as reducing the size, the best way to do that is to look at your code and look at the objects you are using.  And recall, if you are doing a makeWebRequest, extra memory is needed when the json gets converted to a dictionary.  In that case, you may really want to look at how much data you are getting and how complex it is, and look at requesting less data or using a proxy to cut the amount of data to something smaller.

  • thx,

    1. ok

    2. so there is no simple way to find the objects in BAG... removing an checking

    I know that dictionary object in onReceive after webreq consumes about 11kB (tested in another app).

    So next questions :):

    3. Can I annotate (:background) in APP only a few function (needed by background) to decrease size of code of background?
    4. How to hide some code for background?
    - global function without (:background) are hidden automatically,
    - but globals vars/const/enum not, so if I put them in module without (:background) it saves memory? Does module have influence for memory in foreground?

  • AppBase is always part of the background, so you might be able to slim that down.  Globals even if there is no ammotation, are also included so you want to reduce/remove the globals in your app,  And while the dictionary you see may be 11kb, as I said there is a time when the json is being converted into the dictionary, your peak memory will go up a fair amount. but still needs to stay under the 28k max.

    Sounds to me like you'll need to do a proxy to remove the data you don't need from the makeWebRequest response.

  • I can't find table for all devices, so is 32768 the minium for all of them (CIQ >=2.4)?

    You can make your own table by using jq to parse the compiler.json files for all the devices.

    e.g.

    - Open a terminal, change to devices folder (...\Garmin\ConnectIQ\Devices)

    - For Mac, Linux, WSL (Linux on Windows):
     jq -S  '[inputs| { (.deviceId): .appTypes[] | select(.type=="background") | .memoryLimit }]' */compiler.json > background.json

    - For Windows Powershell:
    jq -S '[inputs| { (.deviceId): .appTypes[] | select(.type==\"background\") | .memoryLimit }]' $(get-item *\compiler.json) > background.json

    The output looks like this:

    [
      {
        "approachs62": 65536
      },
      {
        "d2air": 65536
      },
      {
        "d2airx10": 65536
      },
      {
        "d2charlie": 32768
      },
      ...

  • thx, I didn't want to write code, I knew someone already knows it :)

  • thx, I didn't want to write code, I knew someone already knows it :)

    Yeah but I gave you the code you can use to get the data you want, in case you want to look at the table...

    I wasn't lecturing you or asking you to write code yourself.

  • json for this dictionary has only 3kB.... So you think that is rather impossible to increase size free memory so much...

    I don't want to write next proxy, I have a big problem with free servers so rather resign. First try to know the peek but it strange that BAG need additionally memory for converting json because webREQ runs in system area (only background data is in app memory but it shows after exit()).

  • Thx, I've tried and error:

    jq : The term 'jq' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spe
    lling of the name, or if a path was included, verify that the path is correct and try again.

  • You have to download the jq utility, which was linked in the above comment:

    [https://stedolan.github.io/jq/]