Usage of figure() and memory problem

I am trying to output a large number of pictures to files. I

    > don't know the correct usage of figure() in this case, so my
    > program end up devouring memory continuously. I tried to use
    > the clear() method or del, but neither works. Or I didn't
    > use right.

I just ran this test script on my system:

from matplotlib.matlab import *
i = 0
while 1:
    i+=1
    print 'Figure', i
    figure(1)
    plot([1,2,3])
    savefig('somefig')
    close(1)

The critical thing is to call close, otherwise you won't free the
resources (figures are managed by a dictionary so there is a reference
to them behind the scenes). To be safest, I would just reuse
figure(1) each time and issue close(1) at the end of the loop.

However, there is a smallish memory leak even when used correctly. On
my system I went from about 6% memory usage to 18% in generating 3300
figures. Tracking it down will be a top priority, so I'll hopefully
have a fix soon. 99% likelihood it's either in agg or ft2font.

How many figures are you generating and what kind of memory loss are
you seeing? If you use the idiom above, does the situation improve?

JDH