STINNER Victor added the comment: No memory leak if subprocess is spawned in a thread neither: --- import tracemalloc; tracemalloc.start() import subprocess, threading, time, gc
def spawn(event) : subprocess.check_output("true") gc.collect(), gc.collect(), gc.collect() event.set() def func(loops): event = threading.Event() for x in range(loops): event.clear() timer = threading.Timer(0, spawn, (event,)) timer.start() event.wait() func(100) gc.collect();gc.collect();gc.collect();gc.collect() a = tracemalloc.get_traced_memory()[1] print("first", a, "B") loops = 1000 func(loops) gc.collect();gc.collect();gc.collect();gc.collect() b = tracemalloc.get_traced_memory()[1] print("after", loops, "loops, mem:", b, "B") d = (b-a) / loops print("diff: %.1f B/loop" % d) loops = 1000 func(loops) gc.collect();gc.collect();gc.collect();gc.collect() c = tracemalloc.get_traced_memory()[1] print("after", loops, "loops, mem:", c, "B") d = (c-b) / loops print("diff2: %.1f B/loop" % d) --- Output: --- first 1013738 B after 1000 loops, mem: 1014266 B diff: 0.5 B/loop after 1000 loops, mem: 1014318 B diff2: 0.1 B/loop --- Sorry, 0.5 byte/loop is not a memory leak :-) ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue28165> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com