Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
memory leak
import time
import tracemalloc
import pympler.muppy, pympler.summary
import gc
import sys
tracemalloc.start()
collection = []
start = time.time()
while time.time() < start + 60:
key = int(time.time())
collection.append((key, list(range(1,1000))))
while len(collection) > 0 and collection[0][0] < time.time() - 10:
print('pop')
collection.pop()
print("length of dict: {}".format(len(collection)))
gc.collect()
print(tracemalloc.get_traced_memory())
all_objects = pympler.muppy.get_objects()
sum1 = pympler.summary.summarize(all_objects)
pympler.summary.print_(sum1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.