Skip to content

Commit d0b65a7

Browse files
committed
actually delete the "old" menu screen
-> this was a memory leak lv_obj_clean() does not delete the actual object but only the children with lv_obj_create(NULL) we later create a detached new object...
1 parent f399a42 commit d0b65a7

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

lib/3rd_party_adapters/LVGL/Screen.cpp

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,23 @@ static inline void IScreen_leave()
2727
}
2828
}
2929

30+
/**
31+
* this is the way screens are exchanged in this software
32+
*
33+
* @param screen - pointer to new screen to be shown
34+
*/
35+
static void showNewAndDeleteOldScreen(lv_obj_t *screen)
36+
{
37+
/* remember old screen object to delete it after new screnn is displayed */
38+
auto lv_screenOld = lv_scr_act();
39+
40+
/* actually draw the new screen with lvgl */
41+
lv_scr_load(screen);
42+
43+
/* clear the old screen object */
44+
lv_obj_del(lv_screenOld);
45+
}
46+
3047
/**
3148
* @brief Event callback function for an item that calls another submenu
3249
* @note The lvgl event user data hold a pointer to the triggered submenu item
@@ -140,9 +157,6 @@ ScreenMenu::ScreenMenu(const MenuItemList &itemList)
140157
*/
141158
void ScreenMenu::draw()
142159
{
143-
/* clear the current displayed screen */
144-
lv_obj_clean(lv_scr_act());
145-
146160
/* adjust the style so everything has a 1 px padding in all directions */
147161
static lv_style_t style_small_padding;
148162
lv_style_init(&style_small_padding);
@@ -255,8 +269,7 @@ void ScreenMenu::draw()
255269
}
256270
}
257271

258-
/* actually draw the screen with lvgl */
259-
lv_scr_load(screen);
272+
showNewAndDeleteOldScreen(screen);
260273
}
261274

262275
/**
@@ -393,9 +406,6 @@ void ScreenValueModifier::draw()
393406
lv_obj_t *btn;
394407
lv_obj_t *lab;
395408

396-
/* clear the current displayed screen */
397-
lv_obj_clean(lv_scr_act());
398-
399409
/* adjust the style so everything has a 1 px padding in all directions */
400410
static lv_style_t style_small_padding;
401411
lv_style_init(&style_small_padding);
@@ -461,6 +471,5 @@ void ScreenValueModifier::draw()
461471
lv_label_set_text_static(lab, "*");
462472
lv_obj_set_align(lab, LV_ALIGN_CENTER);
463473

464-
/* actually draw the screen with lvgl */
465-
lv_scr_load(screen);
474+
showNewAndDeleteOldScreen(screen);
466475
}

0 commit comments

Comments
 (0)