does python have useless destructors?
Stuart Bishop
stuart at stuartbishop.net
Thu Jun 10 04:22:38 EDT 2004
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 10/06/2004, at 7:51 AM, Terry Reedy wrote:
> "Donn Cave" <donn at u.washington.edu> wrote in message
> news:donn-BCE10C.15003209062004 at nntp3.u.washington.edu...
>> In article <slrnccetd9.gag.msoulier at tigger.digitaltorque.ca>,
>> "Michael P. Soulier" <msoulier at digitaltorque.ca._nospam> wrote:
>>
>>> I recently had a friend tell me that because the Python spec does not
>>> guarantee that an object will necessary be destroyed when all
> references
>>> to it are gone, that desctructors in Python are not reliably called,
> and
>>> thus useless.
>
> To me, this is useless over-dramatization ;-) Is your car useless
> because
> there is no guarantee that the engine will never quit? or the brakes
> fail?
Your metaphor is flawed - *python* is not useless. The __del__ method
is useless. Your metaphor should be 'Are your brakes useless if the
brakes fail?'.
>> - Reference cycles can prevent immediate finalization.
>> If an object holds a reference to itself, however
>> indirectly, it won't be deleted automatically and has
>> to be recovered through garbage collection, and garbage
>> collection won't delete instances with a __del__ method,
>> among other things.
>
> This is admittedly a nuisance. Howver, the original solution was
> reference
> counting only. Programmers had to explictly break loops to reclaim
> resources. This option remains available.
Only if you write everything. Is there any guarantee that cyclic
references will not be introduced into your parent class by your
co-programmer, or in the next release of Zope, Twisted, Python, etc.?
If you use __del__, you are writing fragile code in all but the most
trivial situations (where it is usually unnecessary anyway).
An argument can be made to issue warnings whenever __del__ is defined
if this cannot or will not be fixed.
- --
Stuart Bishop <stuart at stuartbishop.net>
http://www.stuartbishop.net/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (Darwin)
iD8DBQFAyBpTAfqZj7rGN0oRAn+VAKCNRE7BViqQsLz0coRVEd57e1sALwCeKGLl
kwYQAG7QbKJiWteMdv663eQ=
=FBlh
-----END PGP SIGNATURE-----
More information about the Python-list
mailing list