This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author pablogsal
Recipients eric.snow, leezu, pablogsal, pitrou, rhettinger, tim.peters, vstinner
Date 2020-03-02.15:54:29
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
I concur with Antoine and Tim. The GC already has the machinery to deal with weak references in the correct way (even more after recent bugfixes regarding callbacks). Traversing the weak reference list in incorrect because the object does not "own" the weak references to it, as the weak references can die even if the object is alive. Also, as Tim mentions, the traverse will be called on the head of the list, in the same way if you do object.__weakref__ you will only get the HEAD of the list:

>>> import weakref
>>> class A: ...
>>> a = A()
>>> w1 = weakref.ref(a)
>>> w2 = weakref.ref(a, lambda *args: None) # Use a callback to avoid re-using the original weakref
>>> id(w1)
>>> id(w2)
>>> id(a.__weakref__)

I think that this is not very well documented, as there is no pointers on what should and should not be traversed in

I will prepare a PR to the documentation if everybody agrees and another one removing the traverse unless someone sees that something else is at play.
Date User Action Args
2020-03-02 15:54:29pablogsalsetrecipients: + pablogsal, tim.peters, rhettinger, pitrou, vstinner, eric.snow, leezu
2020-03-02 15:54:29pablogsalsetmessageid: <>
2020-03-02 15:54:29pablogsallinkissue39778 messages
2020-03-02 15:54:29pablogsalcreate