Lifetime of a local reference

Thomas Jollans tjol at tjol.eu
Wed Feb 27 18:39:31 EST 2019


On 27/02/2019 22:39, Roel Schroeven wrote:
> Aren't we overthinking this?

No, it's just that nobody had found the evidence you did.

> 
> I think it's pretty clear that a variable is never deleted before it
> goes out of scope. A quick search in the documentation points me to
> (https://docs.python.org/3/reference/datamodel.html#objects-values-and-types):
> 
> 
> "Objects are never explicitly destroyed; however, when they become
> unreachable they may be garbage-collected. An implementation is allowed
> to postpone garbage collection or omit it altogether — it is a matter of
> implementation quality how garbage collection is implemented, *as long
> as no objects are collected that are still reachable*." (emphasis mine)
> 
> In the original example (without del), f is reachable everywhere in the
> function after the initial binding, so it can not be deleted.

Thanks!


-- Thomas



More information about the Python-list mailing list