Python vs Java garbage collection?

A. Lloyd Flanagan alloydflanagan at attbi.com
Mon Dec 23 13:34:56 EST 2002


"Martin v. Löwis" <martin at v.loewis.de> wrote in message news:<au75tt$jd0$04$1 at news.t-online.com>...
> Robert Oschler wrote:
> > A big hearty agreement. I've been pushing the "destructors please" issue for
> > quite some time too.  
> 
> Can you please explain what a destructor is? If it is a fragment of code 
> executed when an object ends its life, what exactly is it that you are 
> pushing? since both Python and Java have such a feature.

A destructor is like a finalization method, it only gets called when
all references to the object are gone.  The difference between C++
destructors and Java's finalize() or Python's __del__() is that C++
_guarantees_ that the destructor will get called sometime before the
program exits (barring a core dump or other catastrophe).  This turns
out to be terribly useful for things like making sure an external
resource gets cleaned up when it's not needed, and not before.

>From the Python reference manual: "It is not guaranteed that __del__()
methods are called for objects that still exist when the interpreter
exits."

So I think what he's saying is that he wants a guarantee that
__del__() gets called at some point, and I agree with him.



More information about the Python-list mailing list