Python vs Java garbage collection?
Derek Thomson
derek at wedgetail.com
Mon Dec 23 04:29:35 EST 2002
Erik Max Francis wrote:
>
> The documentation explicitly says that one should not rely on finalizers
> being called in a timely manner or even at all in some cases. So one
> should not rely on it. I'm really surprised at the level of furor over
> such a basic point that even the documentation specifically mentions.
>
Because some people don't like it, and think it's a step backwards?
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.
--
D.
More information about the Python-list
mailing list