Python vs Java garbage collection?

Robert Oschler Oschler at earthlink.net
Mon Dec 23 08:50:41 EST 2002


"Derek Thomson" <derek at wedgetail.com> wrote in message
news:3IAN9.477$9f.13747 at news.optus.net.au...
> Erik Max Francis wrote:
>  >
>
> What is the point of having destructors, if they might not be called?
> That really annoys me about Java - you can't clean up non-memory
> resources transparently. You must add "close" methods if your instance
> needs to clean up other resources. And if the class suddenly needs it
> where it didn't before, you now need to fix *all* usages of the class.
> So much for encapsulation!
>
> I really think destructors were a step forward in C++, as you couldn't
> forget to call arbitrary cleanup functions like "close". I was happy to
> eliminate them in the step from C to C++, and now in Java and Jython I
> have to use them again. Sigh.
>
> I can see the benefit of mark and sweep in terms of efficiency, but not
> having destructors is a real step backwards for reducing resource leaks
IMO.
>
> One way out within the mark and sweep model might be to make "garbage
> collection" extensible, so that it can manage other limited resources,
> not just memory. That way we could have standard "managers" for files
> and sockets, and we would also be able to add our own.
>
> --

Derek,

A big hearty agreement. I've been pushing the "destructors please" issue for
quite some time too.  I've never heard anyone give a good reason for why
they were dropped from Java.  Most arguments are based on the concept that
"destructors are for memory management" and that Java doesn't need them for
that since it is garbage collected.  But as we both agree "destructors are
also for _resource_ management" and it amazes me that gc based language
developers miss this time and time again.

thx






More information about the Python-list mailing list