1

How can I measure heap usage in Python 3?

I don't mean measuring the size of the allocated virtual memory of a Python process. I want to measure the actual amount of memory used by objects within a Python process. This amount of memory should be tracked by the GC. How can I access such values? Is there an API? (There should be - I just couldn't find it, I suppose ..)

For clarification: I'm not talking about some in-detail profiling. I'm talking about an application giving a rough estimate of how much memory it currently consumes internally. I'm talking about some kind of equivalent to the Runtime.getRuntime().totalMemory() in Java. Some method or function that returns a value in almost no time at all.

Regis May
  • 3,070
  • 2
  • 30
  • 51

0 Answers0