本文主要是介绍【LVGL v8.3】切换界面时内存变化分析,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
文章目录
- 前言
- 实现
- 分析
前言
切换界面需要释放当前控件,否则控件一直存在,同时反复创建会导致内存泄漏
实现
数据结构
static struct
{lv_obj_t *screen;bool screen_del;lv_obj_t *screen_img_bg;
}ui;
创建界面
void setup_scr_ext(void)
{//Write codes screenui.screen = lv_obj_create(NULL);lv_obj_set_size(ui.screen, 800, 480);lv_obj_set_scrollbar_mode(ui.screen, LV_SCROLLBAR_MODE_OFF);//Write codes screen_img_bgui.screen_img_bg = lv_img_create(ui.screen);lv_obj_add_flag(ui.screen_img_bg, LV_OBJ_FLAG_CLICKABLE);lv_img_set_src(ui.screen_img_bg, &_02_alpha_800x480);lv_img_set_pivot(ui.screen_img_bg, 50,50);lv_img_set_angle(ui.screen_img_bg, 0);lv_obj_set_pos(ui.screen_img_bg, 0, 0);lv_obj_set_size(ui.screen_img_bg, 800, 480);lv_obj_add_flag(ui.screen_img_bg, LV_OBJ_FLAG_HIDDEN);//Write style for screen_img_bg, Part: LV_PART_MAIN, State: LV_STATE_DEFAULT.lv_obj_set_style_img_opa(ui.screen_img_bg, 255, LV_PART_MAIN|LV_STATE_DEFAULT);//Update current screen layout.lv_obj_update_layout(ui.screen);lv_scr_load_anim(ui.screen, LV_SCR_LOAD_ANIM_NONE, 100, 100, true);
}
删除界面
void scr_ext_del(void)
{lv_obj_clean(ui.screen);
}
清空图片缓存
lv_img_cache_invalidate_src(NULL);
分析
原始内存
free
memheap pool size max used size available size
---------------- ---------- ------------- --------------
heap_cma 6291456 3090744 3200712
heap_sys 524472 39788 487048
创建界面
free
memheap pool size max used size available size
---------------- ---------- ------------- --------------
heap_cma 6291456 5754480 836560
heap_sys 524472 56972 480800
删除界面
free
memheap pool size max used size available size
---------------- ---------- ------------- --------------
heap_cma 6291456 5754480 836560
heap_sys 524472 56972 484736
释放缓存
free
memheap pool size max used size available size
---------------- ---------- ------------- --------------
heap_cma 6291456 5754480 3200712
heap_sys 524472 56972 486860
小结:主动释放缓存才会作用于 heap_cma;heap_sys 有损耗,需要检查
这篇关于【LVGL v8.3】切换界面时内存变化分析的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!