Detecting memory leaks on apache, mod_python
Fredrik Lundh
fredrik at pythonware.com
Sat Dec 22 02:09:50 EST 2007
Steven D'Aprano wrote:
> Not me.
You're quite knew to this internet thing, aren't you? ;-)
> So... how do you measure memory usage in Python? Every programming
> language I've used before (not a huge range, I'll admit) had *some* sort
> of facility to measure memory usage, typically things like:
>
> * how much memory is free in the stack?
>
> * how much memory is free in the heap?
>
> * how big a block does this pointer point to?
>
> * how much memory does this record/struct/object/string use?
And what languages would that be? I cannot think of a single modern
language that does any of that. Including low-level stuff like C/C++.
And things like "how much memory is free in the heap" isn't even a
meaningful concept on a modern machine, thanks to the wonders of virtual
memory (especially the overcommitting kind).
For Python, standard process monitoring tools (combined with a basic
understanding of how dynamic memory allocation works on modern
platforms) are usually sufficient to get a good view of an application's
memory usage patterns. Just run the program under a few different
scenarios, and see what it does. If the memory use looks suspicious,
use standard debugging techniques to locate the problematic area, and
standard benchmarking techniques to look for unexpected blowups and leaks.
For really hard problems, use the "gc" module, instrumenting memory
allocation libraries (e.g. dmalloc), or C/C++-level debuggers.
</F>
More information about the Python-list
mailing list