Memory fragmentation problem

Description

Hi,
I’m using the 8.2 lvgl library to create an application contains multiple screens where the user needs to navigate.
I’m using only one screen and delete all children and re-create them according to the screen to display.
I noticed that, at a certain point, while I navigate between the screens, lvgl goes into exception and it seems to be due to a memory fragmentation problem.
How can I avoid this? Is it possible navigate between screens without creating and destroying them?

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

NXP i.MX RT1064

What LVGL version are you using?

v8.2

What do you want to achieve?

I’m trying to navigate between screens without create and destroy them

What have you tried so far?

I’m using only one screen and delete all children and re-create them according to the screen to display.

You are running into the memory fragmentation issue because you are deleting the objects and recreating them over and over again. What you need to do is create a new empty object to use as a container. Set the background color to transparent and all of the widgets you use on that second page you make as children of that object. Make the size of the object the same width and height as the display.

use lv_ovj_set_flag(obj, LV_OBJ_FLAG_HIDDEN) once you have created the object. when the page is supposed to be visible you call lv_obj_clear_flag(obj, LV_OBJ_FLAG_HIDDEN)

This will clear the hidden flag so the objects are visible.

Another option is you can just let them be visible all the time and set the positions so it is off screen. when you swipe across the display it will slide the widgets into view.

See here…

1 Like