Skip to content

Instantly share code, notes, and snippets.

@piroyoung
Created January 17, 2018 12:09
Show Gist options
  • Save piroyoung/aebff3d1b0b58e889902b1cc43a223d7 to your computer and use it in GitHub Desktop.
Save piroyoung/aebff3d1b0b58e889902b1cc43a223d7 to your computer and use it in GitHub Desktop.
人為的にメモリリークさせる例
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