Strange behavior with classes deriving from object and weakrefs.
Jeremy Fincher
tweedgeezer at hotmail.com
Wed Jul 31 15:55:58 EDT 2002
I can't say much more than the code itself:
>>> import gc, sys, weakref
>>> class O(object):
pass
>>> o = O()
>>> d = weakref.WeakValueDictionary()
>>> d['o'] = o
>>> d['O'] = O
>>> d.items()
[('O', <class '__main__.O'>), ('o', <__main__.O object at 0x00A116F8>)]
>>> del o
>>> del O
>>> gc.collect()
0
>>> d.items()
[('O', <class '__main__.O'>)]
>>> sys.getrefcount(d['O'])
5
Whence came those 5 references?
Jeremy
More information about the Python-list
mailing list