How to safe exit lvgl

Hi @kisvegabor, on my project lvgl has the following functions:

1. Gui window management, buffer size **800X600**
2. Draw the icon or text fill on the camera display, buffer size is **800X50**

Because there is not enough memory on my device, so when switch between function 1 and function 2, I need to exit lvgl each time, and then reinit lvgl with the new buff size.

If LV_ MEM_CUSTOM set 1, how safely release the resource of each lvgl during switching?

I look forward to your reply to the above questions, thank you ver much!

1 Like

I use lv_disp_remove when exit lvgl, the position B’s memory is about 5K bigger then position A.

show mem     //A
use lvgl
exit lvgl
show mem    //B

Sorry, the version of lvgl is V8.3.3.

1 Like

Hi @kisvegabor, do you know how to safety exit lvgl? I’m waiting for you answer, thanks.

Unfortunately we have no good option now to release all resources with MEM_CUSTOM 1. If the built-in memory manager is used we can easily re-init it and you will have a new empty memory.

So I think the simplest would be to use the internal memory manager (MEM_CUSTOM 0). Is it possible?

But do you really need to reinit the whole LVGL? Isn’t deleting all the screens enough?

I’m very glad get your reply.

Yes, I need to release lvgl resource, because the frame size of two mode is diffrent.

1. Gui window management, buffer size **800X600**
2. Draw the icon or text fill on the camera display, buffer size is **800X50**

I will try with LV_MEM_CUSTOM=0 used lv_disp_remove first, thank you very much!

You can also modify the display’s resolution by calling lv_disp_drv_update.

Sorry, I’m late to answer you, because currently I’m busy in project developing.

Is this code corrent? I use " lv_disp_drv_update" like below, it will crash on my board.

void lv_port_disp_reinit(int hor_size, int ver_size)
    /* Example for 2) */
    static lv_disp_draw_buf_t draw_buf_dsc_2;
    lv_disp_draw_buf_init(&draw_buf_dsc_2, LCD_FRAMME_BUFF_ADDR_1, LCD_FRAMME_BUFF_ADDR_2, hor_size * ver_size);   /*Initialize the display buffer*/
    static lv_disp_drv_t disp_drv;                         /*Descriptor of a display driver*/
    lv_disp_drv_init(&disp_drv);                    /*Basic initialization*/

    /*Set the resolution of the display*/
    disp_drv.hor_res = hor_size ;
    disp_drv.ver_res = ver_size ;

    disp_drv.full_refresh = 0;
    disp_drv.direct_mode = 1;

    /*Used to copy the buffer's content to the display*/
    disp_drv.flush_cb = disp_flush;

    /*Set a display buffer*/
    disp_drv.draw_buf = &draw_buf_dsc_2;

    /*Finally register the driver*/
    lv_disp_drv_update(lv_disp_get_default(), &disp_drv);

When close lvgl, this task will not run until reopen(1. lv_port_disp_reinit 2. set g_run_step to GUI_RUNNING):

static void _disp_thread_main( void *arg )
        if(GUI_STOP == g_run_step){


It looks good at first look. Do you see where it crashes?