My app has 3 “screens”, but can’t keep in memory all at once (only 16K RAM). Is there any simple way to destroy all widgets on screen prior to create new one?
Ideally, i’d like:
Destroy all active screen widgets with allocated memory
Destroy all attached metadata (user data or ext_attr data)
Could not find recommendations in doc about that. Could you advice? I’d like to avoid manual tracking of everything.
You are not allowed to modify the ext_attr pointer directly. That is for internal use by LittlevGL objects. (Although, as mentioned in the other post, you can reallocate it using lv_obj_allocate_ext_attr, and the initial contents will be preserved.)
As a piece of advice, it’s a bad idea to modify any member of the lv_obj_t structure directly (unless we advise you to ) . Instead, use the available helper functions like lv_obj_set_user_data and lv_obj_get_user_data.
I think a good place to free user data would be in the LV_EVENT_DELETE function.
What do you think about additional flag in lv_obj_set_user_data() call, telling lvgl to free memory automatically? There are many cases, when UserData consists of primitive markers & simple types. It would be convenient to have the same gc as with ext_attr
Sometime user_data is used for other propose, other than about lvgl’s obj.
Such as it has a pointer that pointed to a outside variable.
And this outside variable isn’t a heap-mem allocated variable,
and user doen’t want to be cleaned this data when the obj is deleted.
So lvgl in normally will not do any action about your user_data
when the obj is deleting.
However if any data in your obj’s user_data is any lvgl’s obj
that this data is set to be a children of the obj.
therefore when the obj is deleted,
the child obj ( in your user_data) will be deleted automatically.