Some thoughts on garbage collection
Frank Millman
frank at chagford.com
Mon Jan 23 23:44:49 EST 2006
Martin v. Löwis wrote:
> Frank Millman wrote:
> > In principle I agree. My concern was that I might have inadvertently
> > done something wrong (e.g. left a reference dangling) which would
> > prevent gc from removing all objects which I wanted to be removed.
>
> Depends on what it really is that you want to know.
>
> If you want to find out if there are objects which you hold onto
> too long, you can look at len(gc.get_objects()) from time to
> time. This won't be all objects, but just the container objects.
> If you see the number growing over time, you have a leak.
Thank you - this is what I wanted to know.
>
> You could then also categorize this by type, e.g.
>
> frequency = {}
> for o in gc.get_objects():
> o = o.__class__.__name__
> frequency[o] = frequency.get(o, 0) + 1
> print sorted(frequency.iteritems(), key=operator.itemgetter(1),
> reverse=1)
>
Very useful. Thanks.
Frank
More information about the Python-list
mailing list