Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > RE: does python have useless destructors?

Reply
Thread Tools

RE: does python have useless destructors?

 
 
Delaney, Timothy C (Timothy)
Guest
Posts: n/a
 
      06-14-2004
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.

Tim Delaney

 
Reply With Quote
 
 
 
 
David Turner
Guest
Posts: n/a
 
      06-15-2004
"Delaney, Timothy C (Timothy)" <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> 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
contexts.

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).

Regards
David Turner
 
Reply With Quote
 
 
 
 
Ype Kingma
Guest
Posts: n/a
 
      06-15-2004
David Turner wrote:

> "Delaney, Timothy C (Timothy)" <(E-Mail Removed)> wrote in message

news:<(E-Mail Removed)>...
>> 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
> contexts.


It's not that all bets are off. In Jython the __del__() method is called
from java.lang.Object.finalize(), so you can place your bets there:
http://java.sun.com/j2se/1.4.2/docs/...html#finalize()

This javadoc begins with:
"Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object."

The closest thing to a guarantee is to explicitly call the garbage
collector:
http://java.sun.com/j2se/1.4.2/docs/...ystem.html#gc()

From Jython:

import java
java.lang.System.gc()

I wouldn't bet against this, ie. the last time I tried the first call
to this gc() called all __del__() methods instantly on non referenced
Python objects.

>
> 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).


For the moment, try/finally should also be a CPython idiom because
the call to __del__() is not guaranteed there either.

Kind regards,
Ype


--
email at xs4all.nl
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Useless thread about some useless statistics Daniel Nogradi Python 0 11-15-2006 11:33 PM
does python have useless destructors? Michael P. Soulier Python 138 06-22-2004 09:35 AM
RE: does python have useless destructors? Delaney, Timothy C (Timothy) Python 4 06-14-2004 06:38 PM
RE: does python have useless destructors? Tim Peters Python 2 06-12-2004 12:08 AM
RE: does python have useless destructors? Robert Brewer Python 1 06-10-2004 04:29 PM



Advertisments