Memory leak when using lv_freetype

Hi @kisvegabor , @embeddedt

I have a problem with memory when using lv_freetype.
Maybe there’s something that have not been freed.
Could you help me check it.


I am using freetype library + lv_freetype to display ttf font.
I just init font and then destroy it right now to check allocated memory by using lv_mem_monitor.
I use lv_task to call this step (init, destroy font, check mem) each 1s.
Each time, the value of free_size is decreased some kilo-bytes.
After a period of time, free_size ~ 0,
Finally, in lv_ft_font_init_nocache(), face_info = lv_mem_alloc(…) is failed.

What LVGL version are you using?

Lvgl Ver 7.4.0
lv_freetype release/v7


Init font and then destroy, memory size must be back to previous value.
For ex:
free_size = 100
init font => free_size = 90
destroy font => free_size = 100

Code to reproduce




static bool lv_ft_font_init_nocache(lv_ft_info_t * info)
        //FT_Error error = FT_New_Face(library, info->name, 0, &face);
        FT_Error error = FT_New_Memory_Face(library, ttfData, 21684, 0, &face);

My app

static lv_mem_monitor_t mon1;
static void test_memory(lv_task_t * task)
	/* init freetype library */
	lv_freetype_init(64, 1, 0);

	/*Create a font*/ = "font";
	info_1.weight = 30; = FT_FONT_STYLE_NORMAL;

	/*Destroy a font*/

	/*Check memory (mon1.free_size) */

void lv_task_internal_init(void)
	lv_task_t * task = NULL;
	task = lv_task_create(test_memory, 1000, LV_TASK_PRIO_MID, NULL);

I haven’t tested it but you should call lv_freetype_init only once at the beginning of your program.

Ohhh, you’re so cool !!
Thank you very much. I passed it. :smiley: