Hi, I'm using WXAgg by default because I developped an application with GUI using wxpython. But in this case indeed I don't need WXAgg and substituting WXAgg by Agg just work fine, both in the code I submitted as example (see the corrected code at the end) and in the one I'm working with. So yes, probably there is a memory leakage using WXAgg that, as you say, can be an interesting problem for the experts!
Thank you very much for your wise solution (if you are interested, see also the comment of Jakob and my reply, he proposed an elegant solution still using WXAgg). Alain CORRECTED CODE: # BOF import os, tempfile import matplotlib as mpl if mpl.get_backend<>'agg': mpl.use('agg') import matplotlib.pyplot as plt import numpy as np print '\nBackend:\n' + mpl.get_backend() + '\n' def plot_density(filename,i,t,psi_Na): plt.figure(figsize=(8,6)) plt.imshow(abs(psi_Na)**2,origin = 'lower') filename = os.path.join(tempfile.gettempdir(), filename + '_%04d.png'%i) plt.savefig(filename) plt.close() if __name__ == "__main__": x = np.linspace(-6e-6,6e-6,128,endpoint=False) y = np.linspace(-6e-6,6e-6,128,endpoint=False) X,Y = np.meshgrid(x,y) k = 1000000 omega = 200 times = np.linspace(0,100e-3,500,endpoint=False) for i,t in enumerate(times): psi_Na = np.sin(k*X-omega*t) plot_density('wavefunction',i,t,psi_Na) print i # EOF Davidmh wrote: > > I can run the script you provided up to 600 without noticing any > memory growth (TkAgg backend by default). Using the WxAgg, the memory > leak appears. > > If you don't explicitly need WxAgg, I would recommend using TkAgg, or > better Agg if you are not showing the figures. If it is not the case, > more expert and wiser people will have to come to help. > > > On Thu, Jun 16, 2011 at 11:41 AM, Alain Francés <frances08...@itc.nl> > wrote: >> >> Hi, http://old.nabble.com/file/p31858795/ErrorMsg.png >> >> indeed I forgot to remove these line from previous tests, sorry. >> >> However it doesn't affect the code behaviour, the problem remains (it >> fills >> the RAM memory and raises a memory error, see img in att.). >> >> Alain >> >> >> Davidmh wrote: >>> >>> You are importing pylab again before each plot. You have loaded it >>> before. >>> >>> for i,t in enumerate(times): >>> import pylab as pl # <--ERASE THIS >>> >>> >>> >>> On Wed, Jun 15, 2011 at 12:10 PM, Alain Pascal Frances >>> <frances17...@itc.nl> wrote: >>>> Hi, >>>> >>>> I have a script that creates and saves figures in a loop. The memory is >>>> increasing at each figure and is not released back, rising a Memory >>>> error. >>>> I used the close() function on the figure object as well as >>>> gc.collect(), >>>> but no effect. >>>> >>>> I searched on the net and found a similar problem at >>>> http://stackoverflow.com/questions/3623600/python-matplotlib-memory-not-being-released-when-specifying-figure-size. >>>> The problem here was solved using the close() function but in my case, >>>> as >>>> refered before, it doens't work (see code below). >>>> >>>> I'm using Python 2.6.6, matplotlib 1.0.1, WXagg as backend, on >>>> windows7. >>>> >>>> Thanks for help! >>>> >>>> Alain >>>> >>>> >>>> CODE: >>>> >>>> import pylab as pl >>>> import os, tempfile >>>> def plot_density(filename,i,t,psi_Na): >>>> pl.figure(figsize=(8,6)) >>>> pl.imshow(abs(psi_Na)**2,origin = 'lower') >>>> filename = os.path.join(tempfile.gettempdir(), filename + >>>> '_%04d.png'%i) >>>> pl.savefig(filename) >>>> pl.clf() >>>> pl.close() >>>> if __name__ == "__main__": >>>> x = pl.linspace(-6e-6,6e-6,128,endpoint=False) >>>> y = pl.linspace(-6e-6,6e-6,128,endpoint=False) >>>> X,Y = pl.meshgrid(x,y) >>>> k = 1000000 >>>> omega = 200 >>>> times = pl.linspace(0,100e-3,100,endpoint=False) >>>> for i,t in enumerate(times): >>>> import pylab as pl >>>> psi_Na = pl.sin(k*X-omega*t) >>>> plot_density('wavefunction',i,t,psi_Na) >>>> print i >>>> ------------------------------------------------------------------------------ >>>> EditLive Enterprise is the world's most technically advanced content >>>> authoring tool. Experience the power of Track Changes, Inline Image >>>> Editing and ensure content is compliant with Accessibility Checking. >>>> http://p.sf.net/sfu/ephox-dev2dev >>>> _______________________________________________ >>>> Matplotlib-users mailing list >>>> Matplotlib-users@lists.sourceforge.net >>>> https://lists.sourceforge.net/lists/listinfo/matplotlib-users >>>> >>> >>> ------------------------------------------------------------------------------ >>> EditLive Enterprise is the world's most technically advanced content >>> authoring tool. Experience the power of Track Changes, Inline Image >>> Editing and ensure content is compliant with Accessibility Checking. >>> http://p.sf.net/sfu/ephox-dev2dev >>> _______________________________________________ >>> Matplotlib-users mailing list >>> Matplotlib-users@lists.sourceforge.net >>> https://lists.sourceforge.net/lists/listinfo/matplotlib-users >>> >>> >> >> -- >> View this message in context: >> http://old.nabble.com/Memory-increasing-while-plotting-in-loop-tp31850163p31858795.html >> Sent from the matplotlib - users mailing list archive at Nabble.com. >> >> >> ------------------------------------------------------------------------------ >> EditLive Enterprise is the world's most technically advanced content >> authoring tool. Experience the power of Track Changes, Inline Image >> Editing and ensure content is compliant with Accessibility Checking. >> http://p.sf.net/sfu/ephox-dev2dev >> _______________________________________________ >> Matplotlib-users mailing list >> Matplotlib-users@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/matplotlib-users >> > > ------------------------------------------------------------------------------ > EditLive Enterprise is the world's most technically advanced content > authoring tool. Experience the power of Track Changes, Inline Image > Editing and ensure content is compliant with Accessibility Checking. > http://p.sf.net/sfu/ephox-dev2dev > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > > -- View this message in context: http://old.nabble.com/Memory-increasing-while-plotting-in-loop-tp31850163p31861233.html Sent from the matplotlib - users mailing list archive at Nabble.com. ------------------------------------------------------------------------------ EditLive Enterprise is the world's most technically advanced content authoring tool. Experience the power of Track Changes, Inline Image Editing and ensure content is compliant with Accessibility Checking. http://p.sf.net/sfu/ephox-dev2dev _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users