From: Michael D. <md...@st...> - 2009-07-02 14:41:00
|
It is not surprising that memory usage is much lower without printing the plot. Very little is actually done by the "plot" command other than setting up a tree of objects that is later rendered during the printing process (where most of the work happens). The attached script based on what you provided doesn't leak memory for me with matplotlib 0.98.5.2. It would appear that there is something else in your application triggering the leak. Perhaps there is something holding a reference longer than it should? You can see from the attached massif plots that memory usage never becomes unbounded. It is normal for Python to delay deallocation for efficiency reasons. Calling gc.collect (the second graph) does help keep memory usage more compact however, if that is a primary concern. Cheers, Mike Ralf Gommers wrote: > Hi, > > I am working on a PyQt4 application with some embedded MPL figures, > and am also trying to save some figures as png's without displaying > them. I am observing huge memory increases (10s or 100s of Mb) the > moment I try to save a png. I reproduced the issue by combining two > mpl examples, > http://matplotlib.sourceforge.net/examples/user_interfaces/embedding_in_qt4.html > and http://matplotlib.sourceforge.net/examples/api/agg_oo.html. Full > code is attached. When pressing the "save figure" button, memory usage > shoots up, multiple clicks keep sending it higher (although not > monotonically). > > I tested on two different platforms > - Matplotlib 98.5.2 and Python 2.6.2 on Ubuntu. > - latest Enthought Python Distribution on Windows XP. > > The function that does the png saving is: > > def save_png(): > """Save an image as a png file""" > > pngpath = 'test_mplsave.png' > > fig = Figure() > canvas = FigureCanvas(fig) > ax = fig.add_subplot(111) > x = arange(5e3) > ax.plot(x, sin(x)) > canvas.print_figure(pngpath) > > ## tried all things commented out below, all makes no difference ## > #fig.savefig(pngpath) > > #del(fig) > #del(canvas) > #del(ax) > > #import matplotlib.pyplot as plt > #plt.close(fig) > > #import gc > #gc.collect() > > Commenting out the canvas.print_figure line fixes the issue. > > Am I doing something obviously wrong, or mixing two incompatible ways > of doing things? > > Cheers, > Ralf > > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------------ > ------------------------------------------------------------------------ > > _______________________________________________ > Matplotlib-users mailing list > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users -- Michael Droettboom Science Software Branch Operations and Engineering Division Space Telescope Science Institute Operated by AURA for NASA |