Where is memory deallocated in the examples?

Description

In the lv_examples, where is the memory freed again for locally allocated space ? As far as I understand, there is a linked list of GUI objects, which grows depending on the objects created. How can I know, when I need to shrink the list again after not using a particular GUI object anymore ? The variable was declared locally in a function and I don’t have any references outside of it (in the lv_examples) ?

What MCU/Processor/Board and compiler are you using?

Linux

What LVGL version are you using?

7.11.0

What do you want to achieve?

I want to prevent memory leaks.

What have you tried so far?

Tried to understand _lv_ll_ins_head and lv_mem_alloc. Do not fully get it.

Code to reproduce

Code from the exmples (just creating a button inside a function) :

#include "../../lv_examples.h"
* Create a button with a label and react on Click event.
*/
void lv_ex_get_started_1(void)
{
   lv_obj_t * btn = lv_btn_create(lv_scr_act(), NULL);     /*Add a button the current screen*/
   lv_obj_set_pos(btn, 10, 10);                            /*Set its position*/
   lv_obj_set_size(btn, 120, 50);                          /*Set its size*/
   lv_obj_set_event_cb(btn, btn_event_cb);                 /*Assign a callback to the button*/

   lv_obj_t * label = lv_label_create(btn, NULL);          /*Add a label to the button*/
   lv_label_set_text(label, "Button");                     /*Set the labels text*/
}

How do I know in another function, what potion I have to deallocate ?

Many thanks for any hints and best regards :slight_smile:

Hi @H_Schwarz

I understand we must always create a new object with global variable or static variable if it is into the functions. When we don’t need anymore, must free object reference.

Yes, I also would do that way. But in the examples, in many cases it is not implemented that way. Maybe there is a reason for that.

lv_obj_del can be used to remove an object from the screen. This also frees the associated memory.

You also have to use lv_style_reset(&style) to free the memory associated with a style.

Thank you, so it is not advisable to wrap an lv_obj_t* into a std::unique_ptr ?