WeakValueDictionary
Bryan
belred1 at yahoo.com
Sun Oct 3 00:11:37 EDT 2004
Bryan wrote:
> there must be something i don't understand about WeakKeyDictionary and
> WeakValueDictionary. i had expected the last line to be empty because i
> thought i deleted the last strong reference to variable "a". what am i
> misunderstanding?
>
> >>> d = weakref.WeakValueDictionary()
> >>> a = A()
> >>> d[1] = a
> >>> d.items()
> [(1, <__main__.A instance at 0x0116BC60>)]
> >>> del a
> >>> d.items()
> [(1, <__main__.A instance at 0x0116BC60>)]
> >>>
>
> thanks,
>
> bryan
i have another question about weak references. how do you know that b is dead?
>>> a = A()
>>> b = weakref.ref(a)
>>> b
<weakref at 011739F0; to 'instance' at 01135CB0>
>>> del a
>>> b
<weakref at 011739F0; dead>
More information about the Python-list
mailing list