best way to discover this process's current memory usage, cross-platform?

Steven D'Aprano steve at REMOVEMEcyber.com.au
Mon Nov 14 22:57:48 EST 2005


Not sure if I should start a new thread or not, but 
since this is closely related, I'll just leave it as is.

Alex Martelli wrote:

> Having fixed a memory leak (not the leak of a Python reference, some
> other stuff I wasn't properly freeing in certain cases) in a C-coded
> extension I maintain, I need a way to test that the leak is indeed
> fixed.

I would like to investigate how much memory is used by 
Python objects. My motive is 98% pure intellectual 
curiosity and 2% optimization.

I wonder whether I can do something like this:

obj = something()
bytes_used = sizeof(obj)

(obviously there is no built-in function sizeof... 
wait, let me check... nope, not a built-in)

I've read the docs for gc and pdb and nothing stands 
out to me as doing anything like this.


-- 
Steven.




More information about the Python-list mailing list