STM32L5, custom hardware, using Zephyr 3.0, which uses LVGL 7.6.1
I have a custom 128x32 display and need to implement the custom UI / graphics. This is a monochrome display with grayscale.
I’ve got it all working, but every now and then get this error:
Out of memory, can’t allocate a new buffer (increase your LV_MEM_SIZE/heap size
lvgl: Couldn’t allocate memory
I don’t actually think I need to increase the LV_MEM_SIZE/heap size. This is set to 8192. I think the problem is that memory is being dynamically allocated using malloc() (or similar) and it must not be getting freed.
I’ve created my GUI as a series of roughly 45 images. Each image, when shown on the display gets created using lv_img_create. When it’s no longer needed on the display, it’s deleted using lv_obj_del. The source of these created images may change based on what’s needed. For instance, it may be a 5 pixel x 5 pixel square one time, and a 6 pixel x 6 pixel square later on. In this case, lv_img_set_src is invoked (without the deletion and creation of the new image). I’m assuming this may be the cause of my memory leak (trying to assign a 36 pixel image to an image that was created and initially set to a 25 pixel image), or the lv_obj_del function doesn’t always free memory.
I should add that I’m not using screens. Every image is placed on the default screen. I see the value in screens, whereas you can set the image sources on initialization and then just load the screen with lv_scr_load. I’m not sure using this methodology would fix the problem and it would take time to implement.
I would appreciate any tips on how to figure out this memory leak issue. For what it’s worth:
#define CONFIG_LVGL_HOR_RES_MAX 128
#define CONFIG_LVGL_VER_RES_MAX 32
#define CONFIG_LVGL_COLOR_DEPTH_8 1
#define CONFIG_LVGL_MEM_POOL_HEAP_KERNEL 1
#define CONFIG_LVGL_BUFFER_ALLOC_STATIC 1