4
``objgraph`` is a module that lets you visually explore Python object graphs.
5
I've used it in the past to go hunt for memory leaks in Python programs as
6
described by this series of blog posts:
8
* http://mg.pov.lt/blog/hunting-python-memleaks.html
9
* http://mg.pov.lt/blog/python-object-graphs.html
10
* http://mg.pov.lt/blog/object-graphs-with-graphviz.html
12
You'll need `graphviz <http://www.graphviz.org/>`_ if you want to draw
15
.. This is a reStructuredText file. I recommend http://mg.pov.lt/restview
22
Try this in a Python shell:
25
>>> y = [x, [x], dict(x=x)]
27
>>> objgraph.show_refs([y])
29
You should see a graph like this:
31
.. image:: sample-graph.png
32
:alt: [graph of objects reachable from y]
36
>>> objgraph.show_backrefs([x])
40
.. image:: sample-backref-graph.png
41
:alt: [graph of objects from which y is reachable]