[Python-Dev] Weak references
Guido van Rossum
Sun, 05 Nov 2000 21:48:47 -0500
> > - Weak references. This *is* a PEP, but there's no contents yet. We
> > could also try to implement (just) weak dictionaries.
> These already exist... http://www.handshake.de/~dieter/weakdict.html
> mx.Proxy also has an implementation which support weak references.
Thanks. For Fred to read...
> BTW, are these still needed now that we have GC ?
Yes, definitely. Weak dicts are sometimes needed for situations where
a regular dict would keep objects alive forever. E.g. we were made
aware of a "leak" in JPython that could only be fixed with weak dicts:
the Swing wrapper code has a global dict mapping widgets to callback
functions, and this keeps all widgets alive forever. The Java GC
doesn't destroy the widgets, because they are still referenced from
the dict. A weak dict solves this problem nicely (if it weren't that
JDK 1.1 doesn't support weak dicts).
--Guido van Rossum (home page: http://www.python.org/~guido/)