[Tutor] Memory Leak?

Eike Welk eike.welk at gmx.net
Thu May 8 13:52:21 CEST 2008


On Thursday 08 May 2008 00:03, Keith Suda-Cederquist wrote:
> So I started commenting things out until I isolated the problem. 
> For some reason when I plot some of the data using
> pylab/matplotlib, then close the figure using pylab.close() the
> memory doesn't get cleared. (I left this part out of my psedo-code
> in my previous post--Sorry!).

I can reproduce this behavior with the QT-Agg backend on my computer 
too. However when I use a non-interactive backend, the problem goes 
away. 

Backends are explained here:
http://matplotlib.sourceforge.net/backends.html

Here's an example script. The memory usage remains constant. Without 
lines 1 and 2 however the memory usage increases continuously during 
the for loop.



eike at bookxie:~> ipython
Total number of aliases: 15
Python 2.5 (r25:51908, Jan 10 2008, 17:55:29)
Type "copyright", "credits" or "license" for more information.

IPython 0.7.2 -- An enhanced Interactive Python.
?       -> Introduction to IPython's features.
%magic  -> Information about IPython's 'magic' % functions.
help    -> Python's own help system.
object? -> Details about 'object'. ?object also works, ?? prints more.

In [1]:import matplotlib

In [2]:matplotlib.use('Agg')

In [3]:import pylab as pl

In [4]:for i in range(1000):
   .4.:  pl.figure()
   .4.:  pl.plot([1,2,3])
   .4.:  pl.close()
   .3.:

< lines deleted >

Out[4]:[<matplotlib.lines.Line2D instance at 0x8867bec>]
Out[4]:<matplotlib.figure.Figure instance at 0x81b8a4c>
Out[4]:[<matplotlib.lines.Line2D instance at 0x8867a8c>]

In [5]:          



Kind regards,
Eke.


More information about the Tutor mailing list