Message366864
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() |
|
Date |
User |
Action |
Args |
2020-04-20 18:54:19 | a-feld | set | recipients:
+ a-feld, tim.peters, pablogsal, deekay |
2020-04-20 18:54:19 | a-feld | set | messageid: <1587408859.47.0.576042878481.issue40312@roundup.psfhosted.org> |
2020-04-20 18:54:19 | a-feld | link | issue40312 messages |
2020-04-20 18:54:19 | a-feld | create | |
|