getting memory usage of varaibles

Dan Stromberg drsalists at gmail.com
Tue May 2 17:57:41 EDT 2017


On Tue, May 2, 2017 at 12:53 PM, Larry Martell <larry.martell at gmail.com> wrote:
> 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?

This is application-specific, but sometimes it helps to look at the
objects' types, or even their values.



More information about the Python-list mailing list