gc questions

Edward K. Ream edreamleo at charter.net
Wed Jun 18 20:23:20 EDT 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:
        lastObjectsDict[id(o)]=o

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

Edward

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

EKR
--------------------------------------------------------------------
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