How to reduce/release the memory stored by variable images?

I have some memory problem when handing image. we display different images on same page/screen by call lv_img_set_src(lv_obj_t * img, const void * src_img), the memory increases when src_img is not same as the previous image, but doesn’t increase when src_img is same as the previous image. It seems that there’s image caching for image variable. Could you explain why the memory is still not released after calling function lv_obj_del? How to reduce/release the memory? It impacts my platform performance. This memory increase is not expected.

Below is the code. The function display_signal(SignalStrengthId_t sigStrId) is triggered several times. I find memory increases when the function display_signal is triggered at the first time, and memory also increases when the input parameter is not same, but doesn’t increase when input parameter is same as the previous.

static lv_obj_t *sgImgScr3 = NULL;

void clear_img_screen3(void)
{
    if (NULL != sgImgScr3) {
        lv_obj_del(sgImgScr3);
        sgImgScr3 = NULL;
    }
}

void draw_connect_lost()
{
    if (NULL == sgImgScr3) {
        sgImgScr3 = lv_img_create(sgPage, NULL);
    }
    lv_img_set_src(sgImgScr3, &connectLostIdx16);    
    lv_obj_set_pos(sgImgScr3, 50, 50);
}

void draw_wireless_signal(SignalStrengthId_t sigStrId)
{
    // determine image src
    lv_img_dsc_t *wSigImgSrc = NULL;
    switch (sigStrId) {
        case STRENGTH_WEAKEST:
            wSigImgSrc = (lv_img_dsc_t *)&picWSignal1;
            break;
        case STRENGTH_POOL:
            wSigImgSrc = (lv_img_dsc_t *)&picWSignal2;
            break;
		case STRENGTH_NORMAL:
            wSigImgSrc = (lv_img_dsc_t *)&picSignal3;
			break;
        default:
            wSigImgSrc = (lv_img_dsc_t *)&picWSignal1;
            break;
    }

    // display the image
    if (NULL == sgImgScr3) {
        sgImgScr3 = lv_img_create(sgPage, NULL);
	}	   
    lv_img_set_src(sgImgScr3, wSigImgSrc);
	lv_obj_set_pos(sgImgScr3, 138, 63);    
}

void display_signal(SignalStrengthId_t sigStrId)
{
    // clear the screen
    clear_img_screen3();
	
	// draw wireless signal image
	if (sigStrId == NO_SINGAL)
	{
		draw_connect_lost();
	}
	else {
		draw_wireless_signal(sigStrId);   
	}
}

The image cache stores recently used images regardless of whether an image object is still in memory. To clear it you should be able to use lv_img_cache_invalidate_src(NULL), as mentioned in the documentation.

1 Like

Thanks for your replay.
I use the image of LV_IMG_SRC_VARIABLE which stores images as a variable in the internal memory (RAM or ROM). Is this type of image is also for the image caching scheme?Can I think that lv_img_cache_invalidate_src(NULL) is useful for both all types of images(LV_IMG_SRC_VARIABLE/LV_IMG_SRC_FILE/LV_IMG_SRC_SYMBOL)?

I need to display several screens, these screen display changes by swiping the screens. Total more then 100 images are involved and some images display need to last some duration, eg 1 minutes.

Hi,
I tried to use lv_img_cache_invalidate_src(NULL), but nothing changed.
It seems that lv_img_cache_invalidate_src(NULL) is for the image caching of Images stored as files only? In my case, the images stored internally in a variable.

There were some related fixes in the near past. Do you use the latest version of the library?

What is LV_IMG_CACHE_DEF_SIZE in lv_conf.h?

The version is 6.0.
LV_IMG_CACHE_DEF_SIZE is 1.

Please try upgrading to 6.1 and see if it solves the problem.