does python have useless destructors?
dkturner at telkomsa.net
Tue Jun 15 10:16:31 CEST 2004
"Delaney, Timothy C (Timothy)" <tdelaney at avaya.com> wrote in message news:<mailman.957.1087256687.6949.python-list at python.org>...
> David Turner wrote:
> > This will be a pain for the Jython implementers. However, it is
> > doable. Note that I never said the objects couldn't be garbage
> > collected, just that del had to be called at certain well-defined
> > times. What this will involve is the Jython compiler inserting a lot
> > of implicit try/finally constructs.
> > Can anyone see a reason why this scheme wouldn't work?
> Yes - Jython cannot know about references to objects created *in Java
> code*. It is therefore impossible for Jython to maintain reference
> counts when an object is passed to Java (i.e. non-Python) code.
Thank you, Tim, that's the first substantial objection I've heard :-).
So, if Java code makes use of a Python object with __del__, all bets
are off. This is certainly a limitation, but I'm not sure that it's a
very serious one, as RAII objects tend to be used in localized
I think the only available behaviour is simply to ignore the
possibility of an object being referenced externally. Let Java code
use Java idioms (try/finally).
More information about the Python-list