Should i use free() function if i add extra attributes to btn?


I add extra attributes to btn and i want to know do i need use fucntion free() before i use lv_obj_del(btn)?

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

simulator, gcc

What LVGL version are you using?


What do you want to achieve?

In my programm i need to use structure like

typedef struct{
    lv_obj_t ** list_of_obj;
    int ** list_of_coord;

and i want to send pointer to a structure of the given type to event callack function, so i do something like that:


then I fill the structure with the arrays I need.
So the main question is “Do i need to use function free with arguments list_of_obj and list_of_coord before i use lv_obj_del(my_btn)?”


First of all, if you add this to a button your struct need to look like this:

typedef struct{
    lv_btn_ext_t btn_ext; //Keep the button related data
    lv_obj_t ** list_of_obj;
    int ** list_of_coord;

lv_obj_del will simply free the whole ext data of an object (the whole my_struct). It means if list_of_obj and list_of_coord are not dynamically allocated you do not need to do anything.

But if you allocated data into these fields you need to free them explicitly. The best place to do it is LV_EVENT_DELETE.

Yes, that’s what I wanted to know, thanks

1 Like