does python have useless destructors?

John J. Lee jjl at pobox.com
Wed Jun 9 19:04:18 EDT 2004


Donn Cave <donn at u.washington.edu> writes:
[...snip excellent answer...]
> In article <slrnccetd9.gag.msoulier at tigger.digitaltorque.ca>,
> So yes, you can depend on immediate finalization in many
> common situations, but you have to accept the liability of
> a dependence on reference non-circularity and on the C Python.

Adding __del__ methods also, IIRC, has the disadvantage that it messes
up the GC that does reference-cycle collection.  When __del__ was
introduced, Python had no automatic cycle GC.

On balance, considering all these points, I never write __del__
methods any more, and I always (well, almost always) explictly close
files and other external resources.  Other people disagree, preferring
to avoid reference cycles (eg. using the weakref module) and to rule
out Jython.


John



More information about the Python-list mailing list