Hi all,
I'm trying to generate a plot that contains 3 subplots:
2 line plots and a basemap plot showing location. I'm
generating about 200 such plots however my script
doesn't get to complete because it encounters a MemoryError.
I found the test script at http://matplotlib.sourceforge.net/faq.html#LEAKS (which
BTW generates a plot with 4 subplots) and it succeeded
beautifully with no memory issues. However I changed the
last subplot to be a basemap plot and I was able to see
the memory leak. Below is the modified leak test script
I used and the abbreviated output from it. I would truly
appreciate any help on this.
Thanks,
Gerald
···
################################################
#memory leak test
################################################
import os, sys, time
import matplotlib
matplotlib.use('Agg')
from pylab import *
from matplotlib.toolkits.basemap import Basemap
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, 150
for i in range(indEnd):
ind = arange(100)
xx = rand(len(ind))
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))
m = Basemap(0, -85, 360, 85)
m.plot((50,), (20,), 'ro', markersize=12, label='gps')
m.drawcoastlines()
savefig('tmp%d' % i, dpi = 75)
close(1)
val = report_memory(i)
# wait a few cycles for memory usage to stabilize
if i==indStart: start = val
end = val
print 'Average memory consumed per loop: %1.4fk bytes ' % \
((end-start)/float(indEnd-indStart))
################################################
#abbreviated results
################################################
0 42724 12739
1 65068 18359
2 83036 22924
3 100980 27463
4 118928 32027
5 136872 36577
6 154828 41129
7 172784 45681
8 190736 50156
9 208692 54711
10 226644 59272
11 244592 63824
12 262548 68375
13 280496 72926
14 298440 77478
15 316392 81964
.
143 1771824 663458
144 1788924 668010
145 1791316 672561
146 1771104 677112
147 1775644 681599
148 1787288 686166
149 1791604 690718
Average memory consumed per loop: 4505.0833k bytes