Jesse Bacon added the comment:

https://docs.python.org/2/tutorial/stdlib2.html
Section 11.6. Weak References

The example code below from the python tutorial suggests that the value of 'a' 
is not persistent when cast into a WeakValueDictionary as entry 'primary'

The value persisted in the dictionary aver 'a' was deleted and garbage 
collection had been called.  I did not see a bug report for this already 
forgive me if there was one already put in.  

import weakref, gc
class A:
    def __init__(self, value):
        self.value = value
    def __repr__(self):
        return str(self.value)

a = A(10)                   # create a reference
d = weakref.WeakValueDictionary()
d['primary'] = a            # does not create a reference
d['primary']                # fetch the object if it is still alive

del a                       # remove the one reference
gc.collect()                # run garbage collection right away

d['primary']                # entry was automatically removed

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue24123>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to