Table memory leak?

Description

What MCU/Processor/Board and compiler are you using?

PC simulator & STM32F476 (happens in both)

What do you experience?

After deleting a table object that has non-zero number of cells (nr_rows>0 && nr_cols>0), not all memory that was allocated to the table is released according to the values returned by the memory monitor. From some brief experimentation, it looks like the first time during runtime a table is deleted, the leak is of size (16+8N) bytes, and every subsequent time (8+8N) bytes, where N is the total number of cells present in the table. Resetting row and column count to 0 before deleting the object eliminates the leak.

What do you expect?

All memory to be released when a table object is deleted. It can be achieved manually by setting the row and column count of the table to 0 manually before deleting the object, but I expected this cleanup to happen automatically.

Code to reproduce

lv_mem_monitor_t mon;
lv_mem_monitor(&mon);

for (int i=0; i<5; i++) {
	int used1, used2, used3;

	lv_task_handler();
	usleep(5 * 1000);
	lv_mem_monitor(&mon);
	used1 = (int)mon.total_size - (int)mon.free_size;

	//Creating table object
	lv_obj_t *table = lv_table_create(lv_scr_act(), NULL);

	//Create a finite (>0) number of cells in the table
	lv_table_set_row_cnt(table, 1);
	lv_table_set_col_cnt(table, 5);
	lv_task_handler();
	lv_mem_monitor(&mon);
	used2 = (int)mon.total_size - (int)mon.free_size;

	//Uncomment the following to manually empty the table before destroying it, eleiminating the leak
//    	lv_table_set_row_cnt(table, 0);
//    	lv_table_set_col_cnt(table, 0);
	////

	//Delete the table
	lv_obj_del(table);
	lv_task_handler();
	lv_mem_monitor(&mon);
	used3 = (int)mon.total_size - (int)mon.free_size;

	//Print memory usage details
	printf("%d -- Before create, used = %d || After create, used = %d || After destroy, used = %d || LEAK(?) = %d\n", i, used1, used2, used3, used3-used1);

}

Screenshot and/or video

The code above produces the following output:

0 -- Before create, used = 1664 || After create, used = 1944 || After destroy, used = 1720 || LEAK(?) = 56
1 -- Before create, used = 1720 || After create, used = 1992 || After destroy, used = 1768 || LEAK(?) = 48
2 -- Before create, used = 1768 || After create, used = 2040 || After destroy, used = 1816 || LEAK(?) = 48
3 -- Before create, used = 1816 || After create, used = 2088 || After destroy, used = 1864 || LEAK(?) = 48
4 -- Before create, used = 1864 || After create, used = 2136 || After destroy, used = 1912 || LEAK(?) = 48

Thank you for the complete report. I think I’ve found the issue. Can you try the table_memleak_fix branch and see if the problem is resolved?

Yes, this seems to solve the issue, that was quick! thanks.

Great! I’ve merged the fix into master.

1 Like