Actual memory used by an object --- How to Determine?

Josiah Carlson jcarlson at nospam.uci.edu
Fri Feb 20 01:10:18 EST 2004


>   My apologies in advance for asking a
>   question that probably has been raised
>   numerous times already in this newsgroup.
>   My Google search did not lead me to an 
>   answer I could use.
> 
>   Is there a Python module I could use
>   to determine the actual amount of memory
>   used by a Python object, including the 
>   memory used by any subobjects contained
>   therein?

Quick answer: No.

Long answer:
In *nix, there are various programs that tell you the amount of memory a 
resident process is using, my personal favorite for process information 
is ps.  You may be able to query it with the proper string to find the 
total amount of memory Python is using in total, which may or may not be 
useful.  There are utilities for windows that functionally mirror *nix 
ps.  Either could be run from within Python, to be processed with python 
via:
a = os.popen('ps <args...>', 'r')
output = a.read()
a.close()

  - Josiah



More information about the Python-list mailing list