[Stackless] Re: [Python-Dev] _Py_RefTotal wrong in Py 2.2.3

Tim Peters tim at zope.com
Mon Nov 17 12:12:16 EST 2003

[Michael Hudson]
> ...
> One way of getting _Py_RefTotal out of sync is resurrecting objects in
> __del__ methods.

Oops!  That's right:

from sys import gettotalrefcount as g

class C:
    def __del__(self):

alist = []
c1, c2, c3 = C(), C(), C()
del c1, c2, c3

while 1:
    print g(), len(alist),
    del alist[:]

g() goes up by 3 each time around the loop.

		/* If Py_REF_DEBUG, the original decref dropped _Py_RefTotal,
		 * but _Py_NewReference bumped it again, so that's a wash.

Heh.  If you ignore the new reference(s) that resurrected the thing, I
suppose that would be true.  It should (2.3.2) do


to make up for the extra increment done by _Py_NewReference; likewise in
slot_tp_del (BTW, the macro expands to nothing if Py_REF_DEBUG isn't

More information about the Python-Dev mailing list