RFC: Proposal: Deterministic Object Destruction

Rick Johnson rantingrickjohnson at gmail.com
Thu Mar 1 18:35:14 EST 2018


On Wednesday, February 28, 2018 at 10:03:56 PM UTC-6, ROGER GRAYDON CHRISTMAN wrote:
[...]
> If you want something that looks like a real world example,
> consider the very common doubly-linked list:
>
>     [ 1 ] <---> [ 2 ] <---> [ 3 ] <--.....--> [ N ]
> 
> This is chock-full of reference cycles, everywhere you see
> a <-->  Then you have a wrapper List object that has a head
> referencing the 1 node and a tail referencing the N node.
> And you decide you don't need that List any more.
> 
> You could: 
>
> 1) Take the time the code to carefully delete
> every single node in this linked list, taking the time to
> set all of the internal references to None, or

Hmm, not pythonic though.

> 2) Just discard your List object, and let the GC take care
> of the rest.

Agreed. 

And just for the record: I'm not arguing _against_ garbage
collection, more that, since I have always been disturbed by
a Python reality in which __del__ is virtually useless, my
intent here was simply to throw my support behind the
general concept of "Deterministic Object Destruction".

Now, whether or not DOD can be achieved is another matter
altogether. O:-)

Sometimes certain design architectures force us to make
compromises that we'd prefer not to make (GIL, for
instance). And it may be that __del__ is an unfortunate
side-effect of another helpful feature that we cannot bring
our pythonic selfs to live without, and therefore, __del__
was sacrificed in favor of that feature.

And if that is the case, then i can live with it.



More information about the Python-list mailing list