John Hunter wrote:
> On 3/27/07, Eric Firing <[EMAIL PROTECTED]> 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!
>
> JDH
>
> # 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()
>     fig.savefig('test')
>     fig.clf()
>     pylab.close(fig)
>     val = cbook.report_memory(i)
>     print i, val
>     gc.collect()
>     if i==indStart: start = val # wait a few cycles for memory usage
> to stabilize
>
> gc.collect()
> print
> print 'uncollectable list:', gc.garbage
> print
> end = val
> if i > indStart:
>     print 'Average memory consumed per loop: %1.4fk bytes\n' %
> ((end-start)/float(indEnd-indStart))
>   

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:

import os,matplotlib
matplotlib.use('Agg')
from matplotlib.figure import Figure
from matplotlib.cbook import report_memory

def plot():
    fig = Figure()
    i = 0
    while True:
        print report_memory(i)
        fig.clf()
        ax = fig.add_axes([0.1,0.1,0.7,0.7])
        ax.plot([1,2,3])
        i += 1

if __name__ == '__main__': plot()


-Jeff

-- 
Jeffrey S. Whitaker         Phone  : (303)497-6313
Meteorologist               FAX    : (303)497-6449
NOAA/OAR/PSD  R/PSD1        Email  : [EMAIL PROTECTED]
325 Broadway                Office : Skaggs Research Cntr 1D-124
Boulder, CO, USA 80303-3328 Web    : http://tinyurl.com/5telg


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel

Reply via email to