Index: Objects/typeobject.c =================================================================== --- Objects/typeobject.c (revision 45317) +++ Objects/typeobject.c (working copy) @@ -583,8 +583,16 @@ assert(base); } - /* There's no need to clear the instance dict (if any); - the collector will call its tp_clear handler. */ + /* Clear the instance dict (if any), to break cycles involving only + __dict__ slots (as in the case 'self.__dict__ == self'). */ + if (type->tp_dictoffset != base->tp_dictoffset) { + PyObject **dictptr = _PyObject_GetDictPtr(self); + if (dictptr && *dictptr) { + PyObject *dict = *dictptr; + *dictptr = NULL; + Py_DECREF(dict); + } + } if (baseclear) return baseclear(self);