John Hunter wrote:
> On 3/27/07, Eric Firing <efiring@...> wrote:
>> I can add a couple of things to item (1) below. First, the problem
>> occurs only with toolbar2, not with classic or None. Second, a script
>> that illustrates it is attached.
> I defintely agree that this is important -- and it is a big help to
> have a script and the info that you narrowed the problem down to the
> presence of the toolbar. report_memory is platform dependent since ps
> is. I added a report_memory function to cbook so we could have some
> common functionality to rely on. So far it checks for linux or sunos5
> and we should add to this and fix it up as necessary. I also stripped
> the script down to the bare essentials (the memory report) and added
> it to unit/memleak_gui.py so others can use it for testing.
> It turns out if you add a savefig call, TkAgg is terribly (1MB per
> figure) and I can reproduce the smaller toolbar induced leak on my
> platform with TkAgg and GTKAgg. I tried adding some code to
> figure.clf to help, but it didn't. I also spent some time trying to
> figure out what was going wrong with TkAgg but unfortunately did not
> succeed. I don't know anything about Tk, really. One interesting
> thing: the enormous filesave leak in TkAgg also only occurs if the
> toolbar is present. w/o the toolbar, neither gtkagg nor tkagg leak w/
> or w/o the filesave. With the toolbar, both leak a 20-80k w/o the
> file save.
> Developers: if you know something about a particular GUI, try this
> script with -dYourGUIBackend and see if you can isolate the problem!
> # in svn as unit/memleak_gui.py
> #!/usr/bin/env python
> This illustrates a leak that occurs with any interactive backend.
> Run with
> > python memleak_gui.py -dGTKAgg # or TkAgg, etc..
> You may need to edit cbook.report_memory to support your platform
> import os, sys, time
> import gc
> import matplotlib
> #matplotlib.use('TkAgg') # or TkAgg or WxAgg or QtAgg or Gtk
> matplotlib.rcParams['toolbar'] = 'toolbar2' # None, classic, toolbar2
> #matplotlib.rcParams['toolbar'] = None # None, classic, toolbar2
> import pylab
> from matplotlib import _pylab_helpers as ph
> import matplotlib.cbook as cbook
> indStart, indEnd = 30, 50
> for i in range(indEnd):
> fig = pylab.figure()
> val = cbook.report_memory(i)
> print i, val
> if i==indStart: start = val # wait a few cycles for memory usage
> to stabilize
> print 'uncollectable list:', gc.garbage
> end = val
> if i > indStart:
> print 'Average memory consumed per loop: %1.4fk bytes\n' %
John: I just added macos x support in the report_memory function.
Regarding Eric's memory leak #2 (which occurs even for non-gui
backends), here's a simple script to trigger it:
from matplotlib.figure import Figure
from matplotlib.cbook import report_memory
fig = Figure()
i = 0
ax = fig.add_axes([0.1,0.1,0.7,0.7])
i += 1
if __name__ == '__main__': plot()
Jeffrey S. Whitaker Phone : (303)497-6313
Meteorologist FAX : (303)497-6449
NOAA/OAR/PSD R/PSD1 Email : Jeffrey.S.Whitaker@...
325 Broadway Office : Skaggs Research Cntr 1D-124
Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg