Tip for savefig scripts and memory issues

Dear all,

just a small tip for all who are creating many images by using something like this:

for param in range(10):
  data = get_data(param)
  fig = plt.figure()
  ax = fig.add_subplot(111)
  im = ax.imshow(data)
  fig.savefig('data_'+str(param)+'.png)
  # plt.close(fig)

Unfortunately, even so the objects are created inside the loop, it seems they don't vanish completely from loop to loop. So, without the currently commented 'plt.close(fig)' you will create a huge memory leak (well, depending on your image sizes) that grinds even your 4GB Macbook Pro to a complete halt. :wink:

Hopefully that helps some people out.

BR,
Michael