[Python-Dev] r84727 - in python/branches/py3k: Lib/collections.py Misc/NEWS
Antoine Pitrou
solipsis at pitrou.net
Sun Sep 12 12:38:24 CEST 2010
On Sun, 12 Sep 2010 06:12:42 +0200 (CEST)
raymond.hettinger <python-checkins at python.org> wrote:
>
> - # Each link is stored as a list of length three: [PREV, NEXT, KEY].
> + # The back links are weakref proxies (to prevent circular references).
Are you sure this prevents anything? Since your list is circular,
forward links are enough to build a reference cycle.
Actually, this is exemplified here:
> + self.__root = root = _Link() # sentinel node for the doubly linked list
> + root.prev = root.next = root
`root.next = root` is enough to create a cycle, even if you make
root.prev a weakref.
What you need is to make both prev and next weakrefs. All list nodes
all held by the __map dict anyway.
If you are bothered about speed, an alternative would be a classic
finalization scheme, using a class-wide set of OrderedDict weakrefs that
remove themselves and clean up the doubly-linked list when the
OrderedDict becomes dead.
More information about the Python-Dev
mailing list