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 a-feld
Recipients a-feld, deekay, pablogsal, tim.peters
Date 2020-04-20.18:54:19
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1587408859.47.0.576042878481.issue40312@roundup.psfhosted.org>
In-reply-to
Content
Yup agree with all the points above, just wanted to point out that I think self.value is strongly referenced (even though it's just internal references and will be collected by the gc) during Foo.__del__ execution (annotated code below), yet the WeakValueDictionary entry is cleared:

import gc
import sys
import weakref

cache = weakref.WeakValueDictionary()


class Bar:
    pass


class Foo:
    def __init__(self):
        self._self = self
        self.value = Bar()
        cache[id(self.value)] = self.value

    def __del__(self):
        print(sys.getrefcount(self.value))  # -> 2
        # the cache may or may not have self.value at this point
        # even though self.value is strongly referenced!
        print(list(cache.items()))  # -> []


o = Foo()
del o
gc.collect()
History
Date User Action Args
2020-04-20 18:54:19a-feldsetrecipients: + a-feld, tim.peters, pablogsal, deekay
2020-04-20 18:54:19a-feldsetmessageid: <1587408859.47.0.576042878481.issue40312@roundup.psfhosted.org>
2020-04-20 18:54:19a-feldlinkissue40312 messages
2020-04-20 18:54:19a-feldcreate