[Python-Dev] doc change for weakref

Tim Delaney timothy.c.delaney at gmail.com
Sat May 26 00:01:45 CEST 2012


On 26 May 2012 03:46, Antoine Pitrou <solipsis at pitrou.net> wrote:

> On Fri, 25 May 2012 10:21:39 -0700
> Ethan Furman <ethan at stoneleaf.us> wrote:
> > I'd like to make a slight doc change for weakref to state (more or less):
> >
> >     weakrefs are not invalidated when the strong refs
> >     are gone, but rather when garbage collection
> >     reclaims the object
> >
> > Should this be accurate for all implementations, or should it be more
> > along the lines of:
> >
> >     weakrefs may be invalidated as soon as the strong refs
> >     are gone, but may last until garbage collection reclaims
> >     the object
>
> How about: weakrefs are invalidated when the object is destroyed,
> either as a product of all the strong references being gone or the
> object being reclaimed by the :term:`cyclic garbage collector
> <garbage collection>`.
>

I think this could be misleading - it could be read as weakrefs are gone as
soon as all strong refs are gone if there are no cycles. It's
CPython-specific.

IIRC this was exactly Ethan's issue on python-list - he'd made the
assumption that weakrefs went away as soon as all strong refs were gone,
which broke on other Python implementations (and would have also broken if
he'd had cycles).

How about: weakrefs are invalidated only when the object is destroyed,
which is dependent on the garbage collection method implemented.

That then prevents an implementation from invalidating weakrefs before GC -
however, since the object would then be completely unreachable (except by C
code) I'm not sure it matters.

Tim Delaney
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20120526/8cc8fa71/attachment.html>


More information about the Python-Dev mailing list