weakrefs and avoiding bad gc cycles

Martin Pool mbp at canonical.com
Wed Jun 1 07:52:38 UTC 2011

Using a weakref when a plain reference would do is more code, more
complicated, and
more likely to lead to bugs, and might well be slower.  Also, as spiv
points out on irc, more likely to tickle Python implementation bugs.
So we ought to have a good reason to use them, and something more
reliable than just a gut feel that it might be faster.

> I had no idea this simple application of "practicality beats purity"
> will trigger such reactions and I'm kind of sad about that.

The reaction is just that we want to understand why you're doing this
and whether it should be done elsewhere.  If it makes sense to start
following a pattern like eg "always avoid cycles" it's much better if
everyone knows about it.

Anyhow, the bottom line seems to be: don't add them unless there are
measurements showing it actually helps.


More information about the bazaar mailing list