Skip to content

Instantly share code, notes, and snippets.

@philippkeller
Created December 30, 2017 14:00
Show Gist options
  • Select an option

  • Save philippkeller/42bc9bd7c055788fff078fb91e009093 to your computer and use it in GitHub Desktop.

Select an option

Save philippkeller/42bc9bd7c055788fff078fb91e009093 to your computer and use it in GitHub Desktop.
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