1

In a Python script, how can I get the memory usage of all variables in memory?

There are a few questions on here about getting the size or memory of a specified object, which is good, but I'm trying to look for the variables using the most memory (since code might be running on a machine with a memory limit and thus it will throw an error if the used memory becomes too high) so I'd like to somehow profile the current state of ALL variables to see which are causing problems by being too big.

Perhaps something inside a loop through the values of locals(), but I'm not sure if there is a performance concern there that another method might avoid.

tscizzle
  • 11,191
  • 15
  • 54
  • 88
  • Maybe you need a profiling tool or library. Can cProfile help you? – DainDwarf Dec 07 '15 at 15:55
  • 1
    [This answer about memory profiling](http://stackoverflow.com/questions/110259/which-python-memory-profiler-is-recommended) seems relevant, but I would like to see the breakdown of the top memory-using. Anyone know how to do that with Heapy? – tscizzle Dec 07 '15 at 16:25

0 Answers0