Inform the cycle-detector that the a weakref object no longer needs to be
authorFred Drake <fdrake@acm.org>
Thu, 22 Mar 2001 18:05:30 +0000 (18:05 +0000)
committerFred Drake <fdrake@acm.org>
Thu, 22 Mar 2001 18:05:30 +0000 (18:05 +0000)
tracked as soon as it is clear; this can decrease the number of roots for
the cycle detector sooner rather than later in applications which hold on
to weak references beyond the time of the invalidation.

Modules/_weakref.c

index 399b4fe67b55da0646c6446ebf90391b8fe35633..5bdab4dbc0ef96a082af7077f15828d5565dcd71 100644 (file)
@@ -59,6 +59,7 @@ clear_weakref(PyWeakReference *self)
     if (self->wr_object != Py_None) {
         PyWeakReference **list = GET_WEAKREFS_LISTPTR(self->wr_object);
 
+        PyObject_GC_Fini((PyObject *)self);
         if (*list == self)
             *list = self->wr_next;
         self->wr_object = Py_None;
@@ -78,7 +79,6 @@ static void
 weakref_dealloc(PyWeakReference *self)
 {
     clear_weakref(self);
-    PyObject_GC_Fini((PyObject *)self);
     self->wr_next = free_list;
     free_list = self;
 }