Skip to content

Instantly share code, notes, and snippets.

@nfisher
Last active April 18, 2018 20:33
Show Gist options
  • Save nfisher/3b2ff6f0467343c507e666ec8a0ad582 to your computer and use it in GitHub Desktop.
Save nfisher/3b2ff6f0467343c507e666ec8a0ad582 to your computer and use it in GitHub Desktop.
Python: sampling for top referrers to a type
def teardown(self):
# other stuff...
gc.collect()
parents = {}
for o in gc.get_objects():
if not isinstance(o, list):
continue
c = c + 1
if c % 1000 == 0:
print("c", c)
p = random.randint(1, 10)
if p != 1:
continue
for p in gc.get_referrers(o):
t = str(type(p))
parents[t] = parents.get(t, 0) + 1
import operator
off = sorted(parents.items(), key=operator.itemgetter(1), reverse=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment