RFC: Proposal: Deterministic Object Destruction
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Wed Feb 28 23:11:19 EST 2018
On Wed, 28 Feb 2018 18:51:33 -0800, Rick Johnson wrote:
>> What happens if the __del__ method recreates a reference to the object?
>
> So make instantation of the object in its __del__ method an illegal op!
Why should it be illegal? And could that even be enforced in Python?
Is this one of those things where we say "In my ignorance and naivety, I
am unable to imagine why this could be useful after an entire two seconds
of thought, so therefore nobody else could *possibly* find it useful"?
Oh, and by the way, the object is already instantiated. The usual term
here is *resurrection*: the object had no references to it and so was all
but dead the `__del__` method is called, and it does something which ends
up creating a new reference to the object and bringing it back to life.
While it's true that object resurrection can play havoc with certain
(buggy?) compilers[1] and makes the life of the garbage collector more
difficult, there are uses for it:
https://stackoverflow.com/questions/3680281/usages-of-object-resurrection
It is not something I would want to use all the time, but for exceptional
circumstances, object resurrection can be useful.
[1] I'm lead to believe that early versions of Java would dump core under
some circumstances when objects were resurrected.
--
Steve
More information about the Python-list
mailing list