does python have useless destructors?
Isaac To
kkto at csis.hku.hk
Sat Jun 12 10:26:25 EDT 2004
>>>>> "David" == David Turner <dkturner at telkomsa.net> writes:
David> Also, I'd like to point out that destructor semantics and GC are
David> not necessarily related. There's no rule that says the
David> destructor has to be called at the same time as the memory is
David> freed. In fact, there are several good reasons for separating
David> the events.
David> One could conceivably even use a pre-processor to implement
David> Python deterministic destructor semantics in Python. It's really
David> just a case of the compiler inserting a number of implicit
David> try/finally blocks, and reference counting. I can't see any
David> reason why it couldn't be done in Jython.
Unluckily, currently there is no concept of "local scoped objects" in
Python. What it means is that a variable can be local, but an object
cannot. An object in Python is always heap allocated, so there is no way to
know that whether an object has a reference staying outside the current
scope when the current scope exits---short of dictating how the garbage
collector works (i.e., it must count reference). I think the primary
developer in Python has already completely rejected the very idea, probably
because it is impractical to implement in Jython.
Regards,
Isaac.
More information about the Python-list
mailing list