Skip to content

Commit 1586803

Browse files
MNT: optionally collect gc in memleak.py
1 parent 17fd9de commit 1586803

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

tools/memleak.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import numpy as np
1313

1414

15-
def run_memleak_test(bench, iterations, report):
15+
def run_memleak_test(bench, iterations, report, collect):
1616
tracemalloc.start()
1717

1818
starti = min(50, iterations // 2)
@@ -31,7 +31,8 @@ def run_memleak_test(bench, iterations, report):
3131
for i in range(endi):
3232
bench()
3333

34-
gc.collect()
34+
if collect:
35+
gc.collect()
3536

3637
rss = p.memory_info().rss
3738
malloc, peak = tracemalloc.get_traced_memory()
@@ -135,6 +136,8 @@ def __call__(self):
135136
parser.add_argument('--interactive', action='store_true',
136137
help="Turn on interactive mode to actually open "
137138
"windows. Only works with some GUI backends.")
139+
parser.add_argument('--gc-collect', action='store_true',
140+
help="Run `gc.collect()` after every iteration")
138141

139142
args = parser.parse_args()
140143

@@ -146,4 +149,4 @@ def __call__(self):
146149
plt.ion()
147150

148151
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

Comments
 (0)