Marius Gedminas just wrote a post on memory leaks. He could have used Dowser to find the leak more easily, I'll bet.

Dowser is a CherryPy application for monitoring and managing object references in your Python program. Because CherryPy runs everything (even the listening HTTP socket) in its own threads, it's a snap to include Dowser in any Python process. Dowser is also very lightweight (because CherryPy is). Here's how I added it to a Twisted project we're using at work:

... from twisted.application import service application = service.Application("My Server") s.setServiceParent(application) import cherrypy from misc import dowser cherrypy.config.update({'server.socket_port': 8088}) cherrypy.tree.mount(dowser.Root()) cherrypy.engine.autoreload.unsubscribe() # Windows only cherrypy._console_control_handler.unsubscribe() cherrypy.engine.start() from twisted.internet import reactor reactor.addSystemEventTrigger('after', 'shutdown', cherrypy.engine.exit)

The lines before 'import cherrypy' already existed and are here just for context (this is a Twisted service.tac module). Let's quickly discuss the new code:

import cherrypy and dowser. You don't have to stick dowser into a 'misc' folder; that's just how I checked it out from svn. Set the port you want CherryPy to listen on; pick a port your app isn't already using if it's a TCP server. Mount the dowser root. Turn off the CherryPy autoreloader, and the Ctrl-C handler if you're on Windows. I should really turn that off by default in CP. :/ Start the engine, which starts listening on the port in a new thread among other things. Tell Twisted to stop CherryPy when it stops.

Then browse to http://localhost:8088/ and you'll see pretty sparklines of all the objects. Change the URL to http://localhost:8088/?floor=20 to see graphs for only those objects which have 20 or more objects.

Then, just click on the 'TRACE' links to get lots more information about each object. See the Dowser wiki page for more details and screenshots.