Reduce memory usage

I have problem with getting close to the memory limit (~56kb).
My app has about 3000 lines of code, so probably that's the reason.
I disabled all functionality, just run empty view, it took about 50kb.
Looks like even if you don't reference other modules, it load all the code (entry points of classes, methods, static vars and so on).

I don't have almost nothing device-specific, so solution with separating project for different devices will not help.
Are there any other solutions to reduce memory usage?
Or maybe you can explain more about memory management in ConnectIQ (are there any kind of heap, stack, where code and objects storage...).

Thanks in advance
  • I have problem with getting close to the memory limit (~56kb).
    My app has about 3000 lines of code, so probably that's the reason.
    I disabled all functionality, just run empty view, it took about 50kb.
    Looks like even if you don't reference other modules, it load all the code (entry points of classes, methods, static vars and so on).

    I don't have almost nothing device-specific, so solution with separating project for different devices will not help.
    Are there any other solutions to reduce memory usage?
    Or maybe you can explain more about memory management in ConnectIQ (are there any kind of heap, stack, where code and objects storage...).

    Thanks in advance


    It will help to know if you are using layouts, bitmaps, menus, etc. Some of these feature can use quite a bit of memory. I don't use layouts and try not to use images for these particular reasons.
  • I don't have any images and layouts.
    There are a few menus and pickers, but even when I don't load them, memory usage is too high.
  • When I just remove all my UI code, memory reduces to 17kb.
    It doesn't depend on using some module or not (renamed to other and check - memory the same).
    I'm looking at some lazy-loading of modules, which aren't required all the time.
  • I'm looking at some lazy-loading of modules, which aren't required all the time.

    Definitly! Adding a class that is never instantiated reduces memory....

    What I did to reduce memory, was reducing the count of views, and implement a own "view" mechanism ("page") in onUpdate() of my main view....., so drawing different things depending of the selected "page". Same functionality for the user, 15kb less memory...
  • Thank you for the answer, but I don't think it will help.
    I just checked - added simple class with one method, which contains
    var c = 1;
    c = c + 1;
    for(var i = 0; i < c; i++){
    c = c + 8;
    }
    .. repeating the same for 700 lines of code

    It increases memory for ~8kb.
    I didn't create any objects from this class.
    It means that every new line of code increases memory usage and all the code stack stays in the same amount of 64 kb memory, as dynamic objects.
    And it's really a big problem, because it's not possible to implement any more complicated logic, even if you optimize code.
    Garmin developers, could you help?
  • Thank you for the answer, but I don't think it will help.
    I just checked - added simple class with one method, which contains
    var c = 1;
    c = c + 1;
    for(var i = 0; i < c; i++){
    c = c + 8;
    }
    .. repeating the same for 700 lines of code

    It increases memory for ~8kb.
    I didn't create any objects from this class.
    It means that every new line of code increases memory usage and all the code stack stays in the same amount of 64 kb memory, as dynamic objects.
    And it's really a big problem, because it's not possible to implement any more complicated logic, even if you optimize code.
    Garmin developers, could you help?


    What do you mean by "repeating the same for 700 lines of code"? The second issue appears to be that your for loop won't ever exit in this example:

    var c = 1;
    c = c + 1;
    for (var i = 0; i < c; i++) { // i = 0 : c = 2, i = 1 : c = 10, i = 2 : c = 18, ...
    c = c + 8;
    }


    When the for loop is reached the i is less than c and for all future iterations the same is true, it won't exit. I think without something more concrete to look at it will be hard to figure out where all your memory is really being used.
  • No, I mean if you just add random code, which never uses, like

    module T{
    function t(){ // function t never called
    var i = 0;
    i++; i++; i++;
    ...
    //random 700 lines of code
    }
    }

    It increases memory using.
    It doesn't depend in which module code placed or was that module used or not
    The conclusion is one - all code loads into ram at start and there is no possibility to load some peaces of code dynamically.
  • The conclusion is one - all code loads into ram at start and there is no possibility to load some peaces of code dynamically.


    You are correct... All code gets loaded when you start. There's no swapping of code in and out of memory at run time.
  • 370

    Thank you, that what I asked.
    So one possible solution is to remove part of functionality.