RFC: Proposal: Deterministic Object Destruction

Ben Finney ben+python at benfinney.id.au
Sun Mar 4 20:17:46 EST 2018


Richard Damon <Richard at Damon-Family.org> writes:

> […] I can't see any good way to create the equivalent of a 'weak
> reference' (names aren't objects so don't have properties). The  best
> I can think of is to create some sort of magical object that can refer
> to another object, but that reference 'doesn't count'. This seems very
> unPythonic.

Do you mean something like the standard library ‘weakref’ module
<URL:https://docs.python.org/3/library/weakref.html>?

    The weakref module allows the Python programmer to create weak
    references to objects.

    […]
    A weak reference to an object is not enough to keep the object
    alive: when the only remaining references to a referent are weak
    references, garbage collection is free to destroy the referent and
    reuse its memory for something else. However, until the object is
    actually destroyed the weak reference may return the object even if
    there are no strong references to it.

-- 
 \           “The cost of education is trivial compared to the cost of |
  `\                                     ignorance.” —Thomas Jefferson |
_o__)                                                                  |
Ben Finney




More information about the Python-list mailing list