title: Python: how to get size of all objects in current namespace?
body: <p>I have some code that I am running from my own package and the program is using a lot more memory (60GB) than it should be. How can I print the size of all objects (in bytes) in the current namespace in order to attempt to work out where this memory is being used?</p>
  
  <p>I attempted something like </p>
  
  <pre><code>from pympler import asizeof
  
  for objname in dir():
      print(asizeof.asizeof(thing)/1024) # print size in kb
  </code></pre>
  
  <p>But it doesn't work as it just prints the size of the string containing the name of the object in the namespace. Is there a way to get an object reference to everything in the namespace in order to use this method or is there a better method for working out what is using the memory?</p>