Upgraded app from v8.4 to v9.3 - now running out of memory

I have successfully upgraded my project from LVGL version 8.4 to version 9.3. The application starts, but after rendering the splash screen, processing stops. I enabled logging and I can see that LVGL is running out of memory. I am using the ESP32-S3 chip, so I have defined custom memory via:

    #define LV_MEM_CUSTOM_INCLUDE "esp32-hal-psram.h"//
    #define LV_MEM_CUSTOM_ALLOC   ps_malloc
    #define LV_MEM_CUSTOM_FREE    free
    #define LV_MEM_CUSTOM_REALLOC ps_realloc

I realize this is a very general question, but what should I be looking for? Log lines:

PSRAM free before LVGL: 7614368 bytes
Initializing LVGL
[Info]  (0.000, +0)      lv_init: begin lv_init.c:185
[Warn]  (0.000, +0)      lv_init: Style sanity checks are enabled that uses more RAM lv_init.c:317
[Warn]  (0.000, +0)      lv_init: Log level is set to 'Trace' which makes LVGL much slower lv_init.c:321
[Trace] (0.000, +0)      lv_init: finished lv_init.c:395
[I][LvPort][lvgl_v9_port.cpp:0752](lvgl_port_init): Initializing LVGL display driver
[Info]  (0.000, +0)      lv_obj_create: begin lv_obj.c:215
[Info]  (0.000, +0)      lv_obj_create: begin lv_obj.c:215
[Info]  (0.000, +0)      lv_obj_create: begin lv_obj.c:215
[Info]  (0.000, +0)      lv_obj_create: begin lv_obj.c:215
Creating UI
LVGL free: 57356 bytes
Largest block: 57332 bytes

///// here it starts creating all of my objects, and there are a lot of them

//// eventually, i get this log:

LVGL free: 6220 bytes
Largest block: 6200 bytes
[INFO] [Info]   (4.196, +10)     lv_label_create: begin lv_label.c:123
[INFO] [Info]   (4.207, +11)     lv_malloc_zeroed: couldn't allocate memory (104 bytes) lv_mem.c:102
[INFO] [Info]   (4.207, +0)      lv_malloc_zeroed: used: 57560 (100 %), frag:   0 %, biggest free: 40 lv_mem.c:106

If I go back to my application running on v8.4, I have no memory issues. I am using
LV_IMAGE_DECLARE
LV_FONT_DECLARE
for images and fonts to make sure they aren’t part of the heap. Obviously my function/API calls are different between the versions, but type and number of objects, etc is the same between both. Is anyone able to help?

Thanks!

Hello,
I experienced the same problem when upgrading from 8.3 to 9.3.
In 9.x, the custom memory managment function definition has changed.
You must delete all your #define LV_MEM_CUSTOM_XXX
In lv_conf.h (near line 43), replace

#define LV_USE_STDLIB_MALLOC    LV_STDLIB_BUILTIN

by

#define LV_USE_STDLIB_MALLOC    LV_STDLIB_CUSTOM

It’ll prevent LVGL from using standard core lv_malloc/lv_realloc/lv_free functions

Then you must define your own implementation of LVGL core memory functions in a .c file which include the lvgl core header.
On the ESP32-S3 N16R8 i use, it works like a charm (I dynamically load and decode 480x480 png from SD Card).

Here is my lv_custom_mem.c. Beware of the include of the lv_mem.h header


/*********************
 *      INCLUDES
 *********************/
#include "../.pio/libdeps/esp32s3dev/lvgl/src/stdlib/lv_mem.h" // ../lv_mem.h"
#if LV_USE_STDLIB_MALLOC == LV_STDLIB_CUSTOM
#include "esp_heap_caps.h"



/*********************
 *      DEFINES
 *********************/

/**********************
 *      TYPEDEFS
 **********************/

/**********************
 *  STATIC PROTOTYPES
 **********************/

/**********************
 *  STATIC VARIABLES
 **********************/

/**********************
 *      MACROS
 **********************/
/**********************
 *   GLOBAL FUNCTIONS
 **********************/

void lv_mem_init(void)
{
    return; /*Nothing to init*/
}

void lv_mem_deinit(void)
{
    return; /*Nothing to deinit*/

}

lv_mem_pool_t lv_mem_add_pool(void * mem, size_t bytes)
{
    /*Not supported*/
    LV_UNUSED(mem);
    LV_UNUSED(bytes);
    return NULL;
}

void lv_mem_remove_pool(lv_mem_pool_t pool)
{
    /*Not supported*/
    LV_UNUSED(pool);
    return;
}

void * lv_malloc_core(size_t size)
{
    return heap_caps_malloc(size,MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
}

void * lv_realloc_core(void * p, size_t new_size)
{
    return heap_caps_realloc(p, new_size,MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
}

void lv_free_core(void * p)
{
    heap_caps_free(p);
}

void lv_mem_monitor_core(lv_mem_monitor_t * mon_p)
{
    /*Not supported*/
    LV_UNUSED(mon_p);
    return;
}

lv_result_t lv_mem_test_core(void)
{
    /*Not supported*/
    return LV_RESULT_OK;
}

/**********************
 *   STATIC FUNCTIONS
 **********************/

#endif /*LV_STDLIB_CLIB*/

Hope it’ll help

That works, thank you!