[Python-Dev] Java final vs Py __del__

Kepes Krisztian Kepes.Krisztian at peto.hu
Thu Nov 27 06:55:44 EST 2003

Hi !

I very wonder, when I get exp. in java with GC.

I'm Delphi programmer, so I get used to destructorin objects.

In Java the final method is not same, but is like to destructor (I has
been think...).

And then I try with some examples, I see, that the Java GC is
sometimes not call this method of objects, only exit from program.
So: the java programs sometimes end before the GC is use the final
methods on objects.

This mean that in Java the critical operations MUST do correctly by
the programmmers, or some data losing happened.
If it is open a file, then must write the critical modifications, and
must use the flush, and close to be sure to the datas are saved.

In the Py the __del__ is same java's final, or it is to be called in
every way by GC ?

I build this method as safe method: if the programmer don't do any
closing/freeing thing, I do that ?

simple example:

class a:
      def __init__(self,filename):
      def open(self):
      def write(self,data):
      def close(self):
      def __del__(self):
          if self.__file<>None:
          # like destructor: we do the things are forgotten by

Thanx for infos:


More information about the Python-Dev mailing list