mirror of
https://github.com/python/cpython.git
synced 2025-11-25 04:34:37 +00:00
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.
|
||
|---|---|---|
| .. | ||
| .cvsignore | ||
| abstract.c | ||
| boolobject.c | ||
| bufferobject.c | ||
| cellobject.c | ||
| classobject.c | ||
| cobject.c | ||
| complexobject.c | ||
| descrobject.c | ||
| dictobject.c | ||
| enumobject.c | ||
| fileobject.c | ||
| floatobject.c | ||
| frameobject.c | ||
| funcobject.c | ||
| intobject.c | ||
| iterobject.c | ||
| listobject.c | ||
| longobject.c | ||
| methodobject.c | ||
| moduleobject.c | ||
| object.c | ||
| obmalloc.c | ||
| rangeobject.c | ||
| sliceobject.c | ||
| stringobject.c | ||
| structseq.c | ||
| tupleobject.c | ||
| typeobject.c | ||
| unicodectype.c | ||
| unicodeobject.c | ||
| unicodetype_db.h | ||
| weakrefobject.c | ||
| xxobject.c | ||