Matplotlib does not free memory after saving and closing ()

I have a piece of code that loops fine once or twice, but ultimately it builds up memory. I tried to find a memory leak using memory_profiler and this is the result:

 row_nr Memory_usage Memory_diff row_text 470 52.699 MiB 0.000 MiB ax.axis('off') 471 167.504 MiB 114.805 MiB fig.savefig('figname.png', dpi=600) 472 167.504 MiB 0.000 MiB fig.clf() 473 109.711 MiB -57.793 MiB plt.close() 474 109.711 MiB 0.000 MiB gc.collect()' 

I created the drawing as follows: fig, ax = plt.subplots()

Any suggestion where 109 - 52 = 57 MiB went?

I am using Python 3.3.

+6
source share
1 answer
 # Clear the current axes. plt.cla() # Clear the current figure. plt.clf() # Closes all the figure windows. plt.close('all') 

Hope this helps you

0
source

All Articles