~stefanor/objgraph/filename-514422

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
Python Object Graphs
====================

``objgraph`` is a module that lets you visually explore Python object graphs.
I've used it in the past to go hunt for memory leaks in Python programs as
described by this series of blog posts:

* http://mg.pov.lt/blog/hunting-python-memleaks.html
* http://mg.pov.lt/blog/python-object-graphs.html
* http://mg.pov.lt/blog/object-graphs-with-graphviz.html

You'll need `graphviz <http://www.graphviz.org/>`_ if you want to draw
pretty graphs.

.. This is a reStructuredText file.  I recommend http://mg.pov.lt/restview
   for viewing it.


Examples
--------

Try this in a Python shell:

    >>> x = []
    >>> y = [x, [x], dict(x=x)]
    >>> import objgraph
    >>> objgraph.show_refs([y], filename='sample-graph')

You should see a graph like this:

.. image:: sample-graph.png
    :alt: [graph of objects reachable from y]

Now try

    >>> objgraph.show_backrefs([x], filename='sample-backref-graph')

and you'll see

.. image:: sample-backref-graph.png
    :alt: [graph of objects from which y is reachable]