gc questions

Edward K. Ream edreamleo at charter.net
Wed Jun 18 13:39:20 CEST 2003

I have several questions about gc:

1.  The gc documentation says: " This module...provides access to
unreachable objects that the collector found but cannot free."  I thought
the gc could free cycles.  Why would the gc be unable to free objects that
are, in fact, no longer being used?

2. What do the terms "collectable" and "uncollectable" garbage mean?  The gc
will show such objects when gc.set_debug(gc.DEBUG_STATS) is in effect.

3.  I have not been able to do anything with gc.get_objects() except get its
length.  For example, the following throws an exception:

global lastObjectList

objects = gc.get_objects()[:]  # omitting [:] also fails.

if lastObjectList:
            for o in objects: # This can fail!
                        if o not in lastObjectList:
                                    print id(o)
lastObjectList = objects

The exception is thrown at the statement "for o in objects:" and the
exception is a unicode error!

Is there anything obviously wrong in this example? Being able to see which
objects have just been added to the get_objects() list would be most


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