Created
January 17, 2018 12:09
-
-
Save piroyoung/aebff3d1b0b58e889902b1cc43a223d7 to your computer and use it in GitHub Desktop.
人為的にメモリリークさせる例
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import threading | |
import tracemalloc | |
import time | |
tracemalloc.start() | |
class Sub(threading.Thread): | |
def run(self): | |
while True: | |
time.sleep(3) | |
stats = tracemalloc.take_snapshot().statistics('lineno') | |
print('---------------------------------') | |
for line in stats[:30]: | |
print(line) | |
tm = Sub() | |
tm.start() | |
ref = [] | |
def leaker(): | |
dat = 1 | |
ref.append(dat) | |
return None | |
for _ in range(1000000): | |
leaker() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment