]> granicus.if.org Git - python/commit
In the recent python-dev thread "Bizarre new test failure", we
authorGuido van Rossum <guido@python.org>
Mon, 10 Jun 2002 15:24:42 +0000 (15:24 +0000)
committerGuido van Rossum <guido@python.org>
Mon, 10 Jun 2002 15:24:42 +0000 (15:24 +0000)
commita386209754139c13a2a72c53c688172371756a2a
treeada02959efb66979263ca26716d7285915a8eb4a
parent2309498595cb5a69547ad87a66b4574971684ec3
In the recent python-dev thread "Bizarre new test failure", we
discovered that subtype_traverse must traverse the type if it is a
heap type, because otherwise some cycles involving a type and its
instance would not be collected.  Simplest example:
    while 1:
        class C(object): pass
        C.ref = C()
This program grows without bounds before this fix.  (It grows ever
slower since it spends ever more time in the collector.)

Simply adding the right visit() call to subtype_traverse() revealed
other problems.  With MvL's help we re-learned that type_clear()
doesn't have to clear *all* references, only the ones that may not be
cleared by other means.  Careful analysis (see comments in the code)
revealed that only tp_mro needs to be cleared.  (The previous checkin
to this file adds a test for tp_mro==NULL to _PyType_Lookup() that's
essential to prevent crashes due to tp_mro being NULL when
subtype_dealloc() tries to look for a __del__ method.)  The same kind
of analysis also revealed that subtype_clear() doesn't need to clear
the instance dict.

With this fix, a useful property of the collector is once again
guaranteed: a single gc.collect() call will clear out all garbage.
(It didn't always before, which put us on the track of this bug.)

Will backport to 2.2.
Objects/typeobject.c