When will Java go mainstream like Python?

Alf P. Steinbach alfps at start.no
Thu Feb 25 03:35:10 EST 2010


* sjdevnull at yahoo.com:
> On Feb 24, 8:05 pm, Lawrence D'Oliveiro <l... at geek-
> central.gen.new_zealand> wrote:
>> In message <op.u8nfpex8y5e8ok at laptopwanja>, Wanja Gayk wrote:
>>
>>> Reference counting is about the worst technique for garbage collection.
>> It avoids the need for garbage collection.
> 
> That's like saying that driving a VW Beetle avoids the need for an
> automobile.  Reference counting is a form of garbage collection (like
> mark-sweep, copy-collect, and others), not a way of avoiding it.
> 
> You're right that ref counting in many implementations is more
> deterministic than other common forms of garbage collection; IMO,
> Python would be well-served by making the ref-counting semantics it
> currently has a guaranteed part of the language spec--or at least
> guaranteeing that when a function returns, any otherwise unreferenced
> locals are immediately collected.
> 
> I could be convinced otherwise, but I _think_ that that change would
> offer an alternative to all of the interesting cases of where the
> "with" statement is "useful".

Well, relying on ref-counted garbage collection for cleanup actions (other than 
reclaiming memory) is pretty brittle in a language based on general garbage 
collection. As soon as a reference to X sneaks away somewhere, X doesn't clean 
up at scope's end, which is not a catastrophe in itself but means there's no 
telling when it happens or indeed whether it happens at all.

I'm not sure but as I recall the D language has a solution to this, sort of 
declaring X so that no references to it can be retained anywhere, but it's a 
very different language. And Eiffel has the "expanded type" thing for "no 
references", but does it use that to support deterministic cleanup? I don't know 
whether the Eiffel 'dispose' is called for an expanded object.

C# has a 'using' like Python 'with'. It works, sort of, but adds a lot of 
complexity. C++ has the notion of optional garbage collection (formalized in 
C++0x) with cleanup actions not tied to memory reclamation but to 
deterministically invoked destructors and I think that as an /idea/ that is 
clean and good, but in practice almost no-one uses garbage collection with C++, 
and reportedly the least unpopular implementation (the Boehm collector) imposes 
some very stiff requirements on the code.

So I think there's no really good solution: the price for simplicity in one 
dimension is some complexity in another dimension, here deterministic cleanup 
and the problem of zombie objects (garbage collection simplifies a lot of things 
while zombie objects, objects that have had explicit cleanup performed and thus 
are invalid in a sense, compensate by adding back in a lot of complexity).


Cheers,

- Alf



More information about the Python-list mailing list