There has been multiple reports of matplotlib.animation.FuncAnimation
having memory leaks with one example being: Memory leak with FuncAnimation and matshow. #19561 where the cause is related to the C-language implementation. They do post comments that adding the repeat=False
to FuncAnimation
solves the problem.
If that doesnt work (I cant reproduce your fault since i dont have the csv-files) I woul like to inform you of the following:
Your call to gc.Collect() doesnt work as you intend since the garbage Collector only disposes of variables that are not referenced anymore. So even if you call gc.Collect() a hundred times, you wont collect "items" that are still referenced. This is the case with your line agg_by_week = get_data(counter)
.
When you are calling gc.Collect() you are still referencing the data by having the reference: agg_by_week
. If you want to explicitly delete that reference so that it is possible to be collected, use the del
keyword e.g.:
del agg_by_week
more information about the del-keyword can be found Here