[PATCH] store: break up reference cycle introduced in 9cbff8a39a2a

Martin Geisler mg at aragost.com
Thu May 5 02:36:49 CDT 2011


Adrian Buehlmann <adrian at cadifra.com> writes:

> I think the reference cycle in 9cbff8a39a2a goes like this:
>
>       --> fncacheopener object
>      |        |
>      |    local scope of function fncachestore.__init__
>      |        |
>       --- fncache object bound to name fnc
>
> Not sure if that's really a problem though.
>
> With my patch, the references go like this:
>
>        -- fncachestore object
>       |       |
>       |   _fncacheopener object  --
>       |       |                    |
>        -> fncache object           |
>               |                    |
>           object of openertype  <--

I think that very nice drawing should go into the commit message.

But more generally: Python *can* garbage collect some reference cycles,
namely the cycles where none of the object define a destructor. This is
sort of described here:

  http://docs.python.org/library/gc.html#gc.garbage

I just wanted to mention this since it seems that people are hunting
reference cycles just for the sake of hunting them. If removing a cycle
makes the code architecture cleaner then that's perfect -- go ahead! But
if not, then I think we can leave a couple of cycles behind.

-- 
Martin Geisler

aragost Trifork
Professional Mercurial support
http://mercurial.aragost.com/kick-start/


More information about the Mercurial-devel mailing list