lvgl: Out of memory after continues screen update

Hello,

I have built a screen that contains a few variables (labels) that should be updated continuously, for example, it shows the real-time temperature on the screen every 2 seconds or so. the program works well, however after some time, I receiver the below error. and the MCU hangs. Increasing the LV_MEM_Size does not help and I will receive this error just a bit later. it is a matter of time. it seems the buffer does not get refreshed or something like that and each time it just consumes the memory.

Warn: Couldn't allocate memory 	(lv_mem.c #199 lv_mem_alloc())
Warn: Couldn't allocate memory 	(lv_mem.c #306 lv_mem_realloc())
Error: _lv_mem_buf_get 	(lv_mem.c #511 _lv_mem_buf_get())
Error: Out of memory, can't allocate a new buffer (increase your LV_MEM_SIZE/heap size) (0x00000000) 	(lv_debug.c #127 lv_debug_log_error())

This is my code in the loop (the loop gets executed every 3 seconds for example):

lv_obj_clean(lv_scr_act());
setup_scr_screen(&ui, temp, humidity, 25, 17, 45);
lv_scr_load(ui.screen);

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 23 (11 by maintainers)

Most upvoted comments

with the same method that you provided above?

With

lv_obj_t * prev_screen = lv_scr_act();
lv_scr_load(next_screen);
lv_obj_del(prev_screen);

Of sorry, I forgot that you use v7. This docs is for v8. Here is the relevant part of the v7 docs: https://docs.lvgl.io/latest/en/html/overview/style.html#managing-style-list

@kisvegabor I think @MyVanitar is using v7, not v8.

I release the memory using lv_style_reset

That’s correct.

I realized that calling the lv_style_reset causes the styles (or updates) only show once, and not later, even by re-initialization.

You need to tell LVGL that the style is changed. See the docs here.

Regarding styles take a look at this section of the docs: https://docs.lvgl.io/master/overview/style.html#initialize-styles-and-set-get-properties

A common issue is that people call lv_style_init() in their screen create functions which just discards the content of the styles without freeing them. Instead you should initialize the styles once (e.g. in a my_style_init() function) and just use them later.

After screen change you can delete all the previous screen.

You are welcome 🙂

Thank you for the support. You are very professional in the field

Thanks! It’s still only the iteration of the new docs so it’s likely that there are some typos or non-sense sentences. 😅

Anyway, I fixed the remove function names here 26366ad2

I mean haw you called lv_style_init() periodically too? because it doesn’t free the memory allocated in the styles.

Have you called lv_style_init() multiple times?

Based on the code provided, I can see one problem - you never delete lv_scr_act(). However, you can’t do that until after the new screen is loaded. Here is an example:

lv_obj_t * old_scr = lv_scr_act();
lv_obj_clean(old_scr);
setup_scr_screen(&ui, temp, humidity, 25, 17, 45);
lv_scr_load(ui.screen);
lv_obj_del(old_scr);

It’s definitely a memory leak, but we’ll need more info to help. Which LVGL version are you using?