Best practices for reducing memory usage?

Former Member
Former Member

Hi all,

I am currently sitting at 86kb / 91.8kb for my first Garmin watchface, and I'm looking to reduce memory usage. 

So far, I've found the following has helped quite a bit:

  • Reducing the amount of bitmaps being used, when possible (by using fonts or drawing shapes instead)
  • Reducing or removing unused code, such as calls to System.println() and others
  • Only loading fonts necessary to the appropriate screen resolution 

What other memory reduction tips do you have?

Thank you!

  • oh yes, for "set" it is what I always do, but I wonder about efficient way to read the settings "get"

  • only one read vs 5, where each one could hit the fire system In the case of Application.Storage, it will hit the file system each time.

  • and you can put into array different types:

    var ar=["a", 1, 3,5.5, "str1"];

    Application.Storage.setValue(myKey1,ar);

  • Many thanks, but I know about that, my question was about reading the settings in efficient way...

  • put all in one array and do only one call

  •  ??? OK.

    I guess I was not clear enought, sorry about that. 

    We creta a settings. Xml right ?

    To call them we either use App.getApp().getPropery(x) or App.Property.getValue(x)

    In my function Settings I call all the value I need and stock them in Var or Array. 

    But That is not possible to call all of them in 1 time no ? I mean all the app.getProperty (x)

  • There isn't much difference between your first example and your second example. The battery life impact is identical. The memory impact of the 2nd example may be slightly higher as you have one extra function. (Every function you define or piece of code you write takes up memory.) Then again, you may save memory because you only have one class method lookup instead of many. You probably already determined for yourself whether the 2nd one saves memory or not.

    If you have a lot of properties with "numbered names" (as above) and you want to save even more memory on the code that reads them, you can use a loop to read them into an array as you pointed on out. That way instead of having the getProperty() or gAgP() call X times, you only have it once in the body of the loop. It still gets called X times, but you save a small bit of memory by removing those extra lines of code. 

    But there is no way to read multiple properties in a single call, so I don't think there's a way to address your concerns about possibly inefficient multiple filesystem operations.

  • there is difference... it's mixing storage, properties and settings..

    In case off settings I'm not sure (yet) but you can see that you use the same function  to set/get private properties and application settings it means that maybe it's possible to obtain all setting in one call as dictionary see memory

    try it, for example you have a settings GPS

    try to save ...setProperty("GPS",...), it' shouldn't run or you overwrite settings

  • But I don't think there's a way to get all your application settings (or properties) as a dictionary in one call.

    Even if there was, this could negatively impact memory as a dictionary is expensive. (Unless it just returned the same "<Application Settings>" object that you see in the memory viewer.) (Maybe app settings are cached? I don't know exactly how Garmin implements this.)

  • Many thanks that was the answer I needed ! and what I though unfortunately.

    the only way to save memory is the reduce the code so.

    So far I've used App.getApp() for non 2.4 device, but just noticed in dev guide App.AppBase,

    tested both ok, but is there any difference?