Python objgraph
From wikinotes
Library to help identify cause of memory leaks in your program.
Documentation
documentation https://mg.pov.lt/objgraph/ github https://github.com/mgedmin/objgraph
Example
import objgraph objgraph.show_most_common_types() # graphviz object references by class ref = objgraph.by_type('YourClass')[0] objgraph.show_backrefs(ref, 'obj_refs.png') # graphviz object references by instance instance = YourClass objgraph.show_refs(instance, filename='obj_refs.png')
Graphs
objgraph.show_backrefs([var], filename='out.png') # show parents (with reference to obj) objgraph.show_refs([var], filename='out.png') # show children (obj refers to )
Usage Styles
Start/Stop report in code (like breakpoint)
objgraph.show_growth(limit=3) # snapshot mem usage # ... your function ... objgraph.show_growth(limit=3) # displays top-3 changes since first invoke # # MyBigFatObject 2 +2 # dict 797 +1