gc questions

Edward K. Ream edreamleo at charter.net
Thu Jun 19 02:23:20 CEST 2003

Many thanks, Jeremy, for these hints.  Yes, a dictionary speeds things up a
lot.  dict[o] = o won't work for unhashable objects o, so here is the code I
use.  It seems reliable and fast:

    global lastObjectsDict

    objects = gc.get_objects()
    newObjects = [o for o in objects if not lastObjectsDict.has_key(id(o))]

    lastObjectsDict = {}
    for o in objects:

    print "%d new, %d total objects" % (len(newObjects),len(objects))


P.S. I was confused because my code has no __del__ methods.  But Tkinter

Edward K. Ream   email:  edreamleo at charter.net
Leo: Literate Editor with Outlines
Leo: http://webpages.charter.net/edreamleo/front.html

More information about the Python-list mailing list