<p>I want to know the memory usage of my Python application and specifically want to know what code blocks/portions or objects are consuming most memory.
Google search shows a commercial one is <a href="http://www.softwareverify.com/python/memory/index.html" rel="noreferrer">Python Memory Validator</a> (Windows only).</p>

<p>And open source ones are <a href="http://pysizer.8325.org/" rel="noreferrer">PySizer</a> and <a href="http://guppy-pe.sourceforge.net/#Heapy" rel="noreferrer">Heapy</a>.</p>

<p>I haven't tried anyone, so I wanted to know which one is the best considering:</p>

<ol>
<li><p>Gives most details.</p></li>
<li><p>I have to do least or no changes to my code.</p></li>
</ol>

I recommend
Dowser
. It is very easy to setup, and you need zero changes to your code. You can view counts of objects of each type through time, view list of live objects, view references to live objects, all from the simple web interface.
```
```
# memdebug.py

import cherrypy
import dowser

def start(port):
    cherrypy.tree.mount(dowser.Root())
    cherrypy.config.update({
        'environment': 'embedded',
        'server.socket_port': port
    })
    cherrypy.server.quickstart()
    cherrypy.engine.start(blocking=False)
```
```
You import memdebug, and call memdebug.start. That's all.
I haven't tried PySizer or Heapy. I would appreciate others' reviews.
UPDATE
The above code is for
```
CherryPy 2.X
```
,
```
CherryPy 3.X
```
the
```
server.quickstart
```
method has been removed and
```
engine.start
```
does not take the
```
blocking
```
flag. So if you are using
```
CherryPy 3.X
```
```
```
# memdebug.py

import cherrypy
import dowser

def start(port):
    cherrypy.tree.mount(dowser.Root())
    cherrypy.config.update({
        'environment': 'embedded',
        'server.socket_port': port
    })
    cherrypy.engine.start()
```
```