How does one get current variable mem usage?

Jeem nospam at
Thu Feb 19 00:11:47 CET 2004

I'm seeking to tune the memory usage of a python program, having discovered
unexpected swapping.  I would expect that there would be some way to ask the 
interpreter for the total memory usage of all currently live objects, or
even of a specified object.  If such means exist, I haven't found them in
the Python 2.2.2 documentation.  I'm currently making do by reading the
contents of /proc/PID/statm, but that includes not only the interpreter
itself but also space requested from the operating system, but currrently
unused for live variables, and it seems not to go down much when large objects
are killed, e.g. by making them unreachable with varname=""; there are no
obvious other references to the object formerly associated with varname.

Any ideas?

More information about the Python-list mailing list