On Fri, Feb 21, 2003 at 09:39:18AM -0700, Jonathan Corbet wrote:
> [Finding memory leaks]
The attached code might help.  Call it periodically to see what new
"container" objects are getting created.
  Neil
old_count = {}
def count_types():
    import gc, types
    gc.collect()
    new_count = {}
    for o in gc.get_objects():
        t = type(o)
        if t is types.InstanceType:
            k = 'class ' + o.__class__.__name__
        else:
            k = t.__name__
        new_count[k] = new_count.get(k, 0) + 1
    if old_count:
        for k, n in new_count.items():
            old_n = old_count.get(k, 0)
            if n != old_n:
                print k, old_n, '->', n
    old_count.clear()
    old_count.update(new_count)