Low RAM usage strategies

I’m using Tabview to create my UI
I noticed that as I keep adding more and more tabs the RAM usage keeps increasing.

Whay should be the best strategies to develop with low RAM usage in mind?

I notice that almost everything is created with memallocs, is possible to take more use of the FLASH memory?

Can I use Tabview and create page on the fly before it needs to be displayed and free it when page is not displayed?

I’m not understand how styles use affect the RAM or storage usage. What is the impact when I create a new style ? Eg just to change a color of a text

The best strategy is to dynamically populate screens as users browse to them, and delete objects that aren’t visible. This is the most effective way to cut down on RAM usage.

In your case you could create empty tabs but not fill them with content till they are clicked.

oks and is there any callback event for when a tab was destroyed/enabled?

Could you also clarify about the creation/use of styles and how much it effects the RAM?

You can use LV_EVENT_VALUE_CHANGED. I believe the event data would contain the new tab’s index. Inside that event handler you would delete the objects on the other tab and populate the new one. However, you may want to only populate the new tab and set a one-shot lv_task to delete the objects on the other tab ~0.5 seconds later when it’s no longer visible, otherwise, the scrolling animation will look strange.

I can’t provide exact numbers since I haven’t measured this but I can give these general guidelines:

  • Style lists are essentially a constant data structure plus a linked list of properties.
  • Therefore, multiple lv_style_t objects with few properties will take up more space than a single one with many properties.
  • Objects have “local styles”; I’m not 100% sure about this but I believe they are implemented as an lv_style_t built-in to the object. For object-specific overrides, you should use those instead of making a dedicated lv_style_t just for that object.
1 Like

Hello, looks I’m back to this old topic.
I’m started experiment with v8, with a empty initialization.
I undefined the widgets that I dont want to use. I’m undefined the use of a theme.

Under this conditions, LVGL says it is using already 5.3KB RAM

If I add about 14 empty objects it adds more ~4KB and if I add more 14 labels that is more 4KB

so I’m guessing by the end I create my UI I will end out of memory on my MCU? :slight_smile:

Wouldn’t it be possible to reduce more the RAM usage?

(cc @kisvegabor)

One thing I noticed is that there are some features that I dont plan to use, special those on lv_obj_spec_attr_t (groups, scrollbar, pad, scrool, click pad)

Hi,

I made some test on STM32F429 with the following code:

static lv_style_t s;
lv_style_init(&s);
lv_style_set_bg_color(&s, lv_color_hex(0x2080ff));
lv_style_set_bg_opa(&s, LV_OPA_80);
lv_style_set_border_color(&s, lv_color_hex(0x808080));
lv_style_set_border_width(&s, 3);
lv_style_set_radius(&s, 8);
lv_style_set_text_color(&s, lv_color_hex(0xff4499));

for(i = 0; i < 14; i++)  {
    lv_obj_t * obj = lv_obj_create(lv_scr_act());
    lv_obj_set_pos(obj, 10, i *20);
    lv_obj_set_size(obj, 80, 40);
    lv_obj_add_style(obj, &s, 0);

    lv_label_create(obj);
}

Themes are disabled, but all widgets are enabled.

I’ve added the functions gradually to the above code and measured this:

  • Nothing is created: 2.3 kB
  • 14 obj + set pos and size: 3.9 kB (+1.6 kB -> ~115 byte/object)
  • + add style: 3.9 kB
  • + 14 label: 5.7 kB (+1.8 kB -> ~120 byte/object)

It seems normal to me. Please try again with the latest master and if there is no significant change attach your lv_conf.h here.