Memory problem with savefig

Hello, I have been using Matplotlib lately for some

  > academic research. It seem to work just fine. The only
  > serious problem is a problem with memory. When I run
  > the following code, I get the memory increasing
  > linearly with the time. Soon (after around 20
  > generations, and 100 times is this part of the program
  > called) I get beyond the limits of my laptop, and the
  > simulation ends. Considering that I need to do at
  > least 200 generations, you can see that it is a
  > serious problem.

You need to give us a little more information, namely what backend you
are using. Best if you run your script with --verbose-helpful and
post the output it generates,

There are no known signigicant leaks in the Agg backend proper. If
you use TkAgg to create many new canvases (which the script you posted
does), there is a known leak, and it may be on the tk side. The
solution is to reuse the same figure canvas rather than creating new
ones. There is also a small amount of memory that is used up with the
caching of text layout information, which you can clear manually.

Try something like this (untested)

from matplotlib.text import Text
import gc
fig = figure()
for i in range(200):
    fig.clear()
    ax = fig.subplot(111)
    ax.plot(blah)
    fig.savefig('myfig')
    Text.cached = {}
    gc.collect()

See also the FAQ on memory leaks
http://matplotlib.sourceforge.net/faq.html#LEAKS and search the
mailing list archive for "leak" for more inspiration.

Let us know hwat you learn,
JDH