Could you try to use figure() instead of Figure()? That often creates a mess on my side.
Or should one use Figure() in the 'Artist's style? I am still importing pyplot as plt, and in that case, I have to use figure(), otherwise things don't work.
I also had the feeling of a leak and am currently doing this without much 'leaking':
fig = plt.figure()
ax = fig.add_subplot(111)
im = ax.imshow(nData)
cb = plt.colorbar(im)
ax.set_title(bname + ', ' + mode)
fig.savefig(filename + '.equal.png')
I think, the plt.close(fig) was quite important in my case.
Give it a try!
On 2010-04-16 19:18:56 +0200, Keegan Callin said:
I have written a small script that, I think, demonstrates a memory leak
in savefig. A search of the mailing list shows a thread started by Ralf
Gommers <ralf.gommers@...982...> about 2009-07-01 that seems to
cover a very similar issue. I have appended the demonstration script at
the end of this e-mail text.
[keegan@...3070... ~]$ python2.6
Python 2.6.4 (r264:75706, Jan 20 2010, 12:34:05)
[GCC 4.4.2 20091222 (Red Hat 4.4.2-20)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
# Import standard python modules
from ConfigParser import SafeConfigParser as ConfigParser
from cStringIO import StringIO
# import numpy
from numpy import zeros
# Import matplotlib
from matplotlib.figure import Figure
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
'''Returns a new figure containing array a.'''
# Create figure and setup graph
fig = Figure()