getting memory usage of varaibles

Larry Martell larry.martell at gmail.com
Tue May 2 15:53:43 EDT 2017


I have a script that consumes more and more memory as it runs. It has
no globals and the large data structures go out of scope often so
should be garbage collected. I've looked at the most likely suspects
with sys.getsizeof and they are not growing in size. I did this:

sum([sys.getsizeof(o) for o in gc.get_objects()])

And I can see it getting larger and larger. But I want to see what it
is that is causing this. My thought was to put all the objects in a
dict with their sizes and compare them as the program runs and report
on the one that are growing. But I can't get the name of the object
from gc.get_objects only the id.

Anyone have any thoughts on how I can monitor the variables' memory
usage as the script runs?



More information about the Python-list mailing list