diff options
author | Guido van Rossum <guido@python.org> | 2002-06-10 15:24:42 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2002-06-10 15:24:42 (GMT) |
commit | a386209754139c13a2a72c53c688172371756a2a (patch) | |
tree | ada02959efb66979263ca26716d7285915a8eb4a /Misc | |
parent | 2309498595cb5a69547ad87a66b4574971684ec3 (diff) | |
download | cpython-a386209754139c13a2a72c53c688172371756a2a.zip cpython-a386209754139c13a2a72c53c688172371756a2a.tar.gz cpython-a386209754139c13a2a72c53c688172371756a2a.tar.bz2 |
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.
Diffstat (limited to 'Misc')
0 files changed, 0 insertions, 0 deletions