diff -r 54a77c556d9a Objects/typeobject.c --- a/Objects/typeobject.c Wed Dec 14 22:53:13 2011 -0600 +++ b/Objects/typeobject.c Thu Dec 15 11:33:45 2011 +0000 @@ -276,6 +276,7 @@ return -1; } Py_DECREF(tmp); + PyType_Modified(type); tp_name = _PyUnicode_AsString(value); if (tp_name == NULL) @@ -304,6 +305,7 @@ type->tp_name, Py_TYPE(value)->tp_name); return -1; } + PyType_Modified(type); et = (PyHeapTypeObject*)type; Py_INCREF(value); @@ -998,8 +1000,6 @@ _PyObject_GC_TRACK(self); assert(basedealloc); basedealloc(self); - - PyType_Modified(type); /* Can't reference self beyond this point */ Py_DECREF(type); @@ -2775,6 +2775,10 @@ /* Because of type_is_gc(), the collector only calls this for heaptypes. */ assert(type->tp_flags & Py_TPFLAGS_HEAPTYPE); + + /* Method-cache contains borrowed refs to items in tp_dict, + so it must be cleared before the collector clears the dict */ + PyType_Modified(type); /* The only field we need to clear is tp_mro, which is part of a hard cycle (its first element is the class itself) that won't