This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients The Compiler, Xavion, r.david.murray, vstinner, ztane
Date 2016-09-19.22:58:35
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1474325915.5.0.0425436957273.issue28165@psf.upfronthosting.co.za>
In-reply-to
Content
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 :-)
History
Date User Action Args
2016-09-19 22:58:35vstinnersetrecipients: + vstinner, r.david.murray, ztane, The Compiler, Xavion
2016-09-19 22:58:35vstinnersetmessageid: <1474325915.5.0.0425436957273.issue28165@psf.upfronthosting.co.za>
2016-09-19 22:58:35vstinnerlinkissue28165 messages
2016-09-19 22:58:35vstinnercreate