(If you’ve installed xdot, omit the filename argument to get the
interactive viewer.)

You should see a graph like this:

If you prefer to handle your own file output, you can provide a file object to
the output parameter of show_refs and show_backrefs instead of a
filename. The contents of this file will contain the graph source in DOT format.

It’s easy to see MyBigFatObject instances that appeared and were
not freed. I can pick one of them at random and trace the reference chain
back to one of the garbage collector’s roots.

For simplicity’s sake let’s assume all of the roots are modules. objgraph
provides a function, is_proper_module(), to check this. If
you’ve any examples where that isn’t true, I’d love to hear about them
(although see Reference counting bugs).

Bugs in C-level reference counting may leave objects in memory that do not
have any other objects pointing at them. You can find these by calling
get_leaking_objects(), but you’ll have to filter out legitimate GC
roots from them, and there are a lot of those:

I’ve developed a set of functions that eventually became objgraph when I
was hunting for memory leaks in a Python program. The whole story – with
illustrated examples – is in this series of blog posts: