Skip to content

Commit cacf95d

Browse files
committed
added some more memleak unit tests
svn path=/trunk/matplotlib/; revision=427
1 parent a6d75b2 commit cacf95d

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

unit/memleak_hawaii3.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import os, sys, time
2+
import matplotlib
3+
matplotlib.use('Agg')
4+
from matplotlib.matlab import *
5+
6+
7+
def report_memory(i):
8+
pid = os.getpid()
9+
a2 = os.popen('ps -p %d -o rss,sz' % pid).readlines()
10+
print i, ' ', a2[1],
11+
return int(a2[1].split()[1])
12+
13+
14+
15+
# take a memory snapshot on indStart and compare it with indEnd
16+
indStart, indEnd = 10, 200
17+
for i in range(indEnd):
18+
ind = arange(100)
19+
xx = rand(len(ind))
20+
figure(1)
21+
subplot(221)
22+
plot(ind, xx)
23+
subplot(222)
24+
X = rand(50,50)
25+
imshow(X)
26+
27+
subplot(223)
28+
scatter(rand(50), rand(50))
29+
subplot(224)
30+
pcolor(10*rand(50,50))
31+
savefig('tmp%d' % i, dpi = 75)
32+
close(1)
33+
34+
val = report_memory(i)
35+
if i==indStart: start = val # wait a few cycles for memory usage to stabilize
36+
37+
end = val
38+
print 'Average memory consumed per loop: %1.4fk bytes\n' % ((end-start)/float(indEnd-indStart))
39+
40+
"""
41+
Average memory consumed per loop: 0.0053k bytes
42+
"""

0 commit comments

Comments
 (0)