Python vs Java garbage collection?

Robert Oschler Oschler at earthlink.net
Mon Dec 23 11:28:15 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.
>
> If it is an explicit statement "this object ends its life now":
> a) what happens to references that still exist to that object? and
> b) why can't you use a method for that?
>

Martin,

I don't want to reiterate what's already been said on this thread so pardon
the brief reply, but Python:__del__ and Java:finalize() cannot be relied
upon to be called as soon as an object's reference count goes to 0, so they
"have the feature" but not the call timing guarantee.  In C++, using an
auto_ptr example, the instant an object's reference count goes to 0 it's
destructor will be called.  So if I'm using a critical resource like a
file/record lock, or  perhaps a scarce resource like a speech reco engine, I
can feel confident with C++ that as soon as it's no longer needed by one
part of the program, it will become available for another, and I don't have
make the the cleanup call (destructor) myself so I don't run the risk of
forgetting to make a cleanup call.

thx






More information about the Python-list mailing list