''Out of memory..." asserted in lv_mem.c

I have a function periodically executed every 2 seconds, and after it runs about 4 hours, ''Out of memory, can’t allocate a new buffer (increase your LV_MEM_SIZE/heap size)" asserted in lv_mem.c @line 584. I have set LV_MEM_SIZE (36U *1024U), I think it is big enough for a screen with 256 * 64 of monocolour. And code is like this:
static char ucItem_Val[64] ={ 0};
static char *pChar = &ucItem_Val[0];
void Lcd_menu_disp(struct stlcd_menu_page_info *pmenu)
if(lv_scr_act() != main_page.lv_main_scr)
MenuItem_S (*pTempMenuItem)[] = pmenu->pMenuItem;
MenuItem_S *pItem = (MenuItem_S *)(*pTempMenuItem);
pItem = pItem + pmenu->ucFirstItemIdx;
int i = 0;
while(i < MAX_ITEM_PER_PAGE)
memset(ucItem_Val, 0, 64);
lv_label_set_text(main_page.lv_label_item[i], “”);
lv_obj_clean_style_list(main_page.lv_label_item[i], LV_LABEL_PART_MAIN);

    pChar = &ucItem_Val[0];
    if(NULL != pItem->Item)
        strcat(ucItem_Val, pItem->Item);
        pChar += strlen(pItem->Item);

    if(NULL != pItem->pValue)

        memcpy(pChar, pItem->pValue->Value, PARAM_VAL_LEN);

    if(i < pmenu->ucItemCount)
        lv_label_set_text(main_page.lv_label_item[i], ucItem_Val);
        if((i + pmenu->ucFirstItemIdx) == pmenu->ucMenuItemIdx)
            static lv_style_t style;
            lv_style_set_bg_color(&style, LV_STATE_DEFAULT, LV_COLOR_BLACK);
            lv_style_set_bg_opa(&style, LV_STATE_DEFAULT, LV_OPA_COVER);
            lv_style_set_text_color(&style, LV_STATE_DEFAULT, LV_COLOR_WHITE);
            lv_obj_add_style(main_page.lv_label_item[i], LV_LABEL_PART_MAIN, &style);

main_page.lv_label_item[] are created at initializing time for once. I can’t find out which part caused the memory leakage. Need Help!
Thank you very much!

Has the message says, you probably want to increase LV_MEM_SIZE in the lv config file. This size is independent of the driver rendering buffer.

I presume that your system has sufficient free memory to increase LV_MEM_SIZE. If you are not sure, ask around how to figure that out for your specific cpu. Typically this is determined by subtracting the heap top (s break) from the stack’s bottom.

There should be a function within the heap management which allows you to read the current free heap size.
Call this every time when your periodically function is executed (maybe on entering and on exit) and take a look whether this value is decreasing over time.

Thank you all for responses! I think my problem is same as this one:
“[SOLVED] [memory leak] [master branch] I face a problem when call lv_label_set_text() function periodicity to refresh date]”

I didn’t see a free functions destroy. May be the problem is you allocate memory all the time and your stack is growing all the time.

The problem still exists! I doubt it is the function lv_obj_add_style that is called periodically for a long time in my code. Will it cause memory leak?

Are you ever removing the styles? If not, this will definitely cause a memory leak.

every time before lv_obj_add_style is called, lv_obj_clean_style_list is called first, will it make sense?

I could be wrong, but I think you probably need to call lv_style_reset on the styles themselves as well.

I may get it, lv_obj_add_style must consume memory, only the reset style to release it, lv_obj_clean_style_list works on the label cotrol, and will not release style’s memory.