[Zope-dev] debugging memory leaks
Barry Pederson
bp at barryp.org
Tue Oct 28 14:43:27 EST 2003
Seb Bacon wrote:
> So, say Foo is leaking because it is referenced from O which can't be
> collected. Given 100 things which refer to Foo, how do I identify which
> one is O? And of course, then O may be leaking because it is referenced
> from P...
I've been looking into memory leaks of my own, and put together a small
module that outputs the information available from the gc.garbage list in a
format that Graphviz (http://www.research.att.com/sw/tools/graphviz/) can
then render as an image (GIF, SVG, etc) that makes it a bit easier to see the
cycles.
Here's a sample image:
http://barryp.org/misc/simpletal_visualize/test2.gif
Here's the code
http://barryp.org/misc/simpletal_visualize/visualize_pyobjects.py
It shouldn't be too hard to use that in your own code, something like:
import visualize_pyobjects
gc.collect()
cycles = visualize_pyobjects.prune_stems(gc.garbage)
visualize_pyobjects.create_dot(cycles, '/tmp/foo.dot')
and then, run the graphviz 'dot' program from the command line to create a
GIF file:
dot -Tgif </tmp/foo.dot >/tmp/foo.gif
(use a '-Tsvg' option to create an SVG file, which is smaller and easily
viewed and edited with things like sodipodi I believe)
Barry
More information about the Zope-Dev
mailing list