From: John H. <jdh...@ac...> - 2006-02-10 17:18:24
|
>>>>> "aurelien" == aurelien gourrier <aur...@fr...> writes: aurelien> Dear all, I posted a message two days ago mentionning aurelien> memory problems while saving a large number of images, aurelien> which I guess was not so clear... I've worked a bit on aurelien> it and I think the questions seem clearer to me now. I aurelien> have paid particular attention to the threads in the aurelien> user mailing list dealing with memory problems. What happens if you explicitly name the figure (ef figure(1)) for i in range(indEnd): figure(1) subplot(221) plot(ind, xx) subplot(222) X = rand(50,50) imshow(X) subplot(223) scatter(rand(50), rand(50)) subplot(224) pcolor(10*rand(50,50)) savefig('tmp%d' % i, dpi = 75) close(1) See also the FAQ http://matplotlib.sourceforge.net/faq.html#LEAKS which shows the canonical way to make multiple plots to prevent leaks, namely, pairing a close with each figure creation? I'm not sure why you are seeing a problem right now, but my memory leak test script memleak_hawaii3.py does not appear to be leaking #!/usr/bin/env python import os, sys, time import matplotlib #matplotlib.interactive(True) #matplotlib.use('Cairo') matplotlib.use('Agg') from pylab import * def report_memory(i): pid = os.getpid() a2 = os.popen('ps -p %d -o rss,sz' % pid).readlines() print i, ' ', a2[1], return int(a2[1].split()[1]) # take a memory snapshot on indStart and compare it with indEnd indStart, indEnd = 30, 201 for i in range(indEnd): figure(1); clf() subplot(221) t1 = arange(0.0, 2.0, 0.01) y = sin(2*pi*t1) plot(t1,y,'-') plot(t1, rand(len(t1)), 's', hold=True) subplot(222) X = rand(50,50) imshow(X) subplot(223) scatter(rand(50), rand(50), s=100*rand(50), c=rand(50)) subplot(224) pcolor(10*rand(50,50)) savefig('tmp%d' % i, dpi = 75) close(1) val = report_memory(i) if i==indStart: start = val # wait a few cycles for memory usage to stabilize end = val print 'Average memory consumed per loop: %1.4fk bytes\n' % ((end-start)/float(indEnd-indStart)) |