12
12
import numpy as np
13
13
14
14
15
- def run_memleak_test (bench , iterations , report ):
15
+ def run_memleak_test (bench , iterations , report , collect ):
16
16
tracemalloc .start ()
17
17
18
18
starti = min (50 , iterations // 2 )
@@ -31,7 +31,8 @@ def run_memleak_test(bench, iterations, report):
31
31
for i in range (endi ):
32
32
bench ()
33
33
34
- gc .collect ()
34
+ if collect :
35
+ gc .collect ()
35
36
36
37
rss = p .memory_info ().rss
37
38
malloc , peak = tracemalloc .get_traced_memory ()
@@ -135,6 +136,8 @@ def __call__(self):
135
136
parser .add_argument ('--interactive' , action = 'store_true' ,
136
137
help = "Turn on interactive mode to actually open "
137
138
"windows. Only works with some GUI backends." )
139
+ parser .add_argument ('--gc-collect' , action = 'store_true' ,
140
+ help = "Run `gc.collect()` after every iteration" )
138
141
139
142
args = parser .parse_args ()
140
143
@@ -146,4 +149,4 @@ def __call__(self):
146
149
plt .ion ()
147
150
148
151
run_memleak_test (
149
- MemleakTest (args .empty ), args .iterations [0 ], args .report [0 ])
152
+ MemleakTest (args .empty ), args .iterations [0 ], args .report [0 ], args . gc_collect )
0 commit comments