When will Java go mainstream like Python?
Alf P. Steinbach
alfps at start.no
Fri Feb 26 01:41:29 CET 2010
* Chris Gray:
> Lawrence D'Oliveiro <ldo at geek-central.gen.new_zealand> writes:
>> 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. It means I can write things like
> I'm by no means an expert, but how does reference counting deal with
> arbitrary long cycles of references (btw I've *written* a simple
> reference counter for a programming language)?
Generally it doesn't. Some solutions have however been proposed for
std::shared_ptr in C++. None have made it to any noteworthy status, but they
demonstrate that there are more or less practical solutions for the most common
Currently the upshot is that if you need the kind of self-referential spaghetti
structure (no offense) created by mathematical expressions that refer to each
other, then you've passed beyond what can be handled practically by reference
counting alone or even in combination with cycle handling techniques.
For that you're better off with some functional language, or Python... ;-)
> When I asked someone whose knowlege of Java I trust, he said that modern
> Java's do both reference counting and garbage collection. That was 2 or 3
> years ago. I would have guessed that Python was the same.
Yes, Python adds general garbage collection to deal with cycles.
Essentially the reference counting deals efficiently and immediately with
objects created by expression evaluation, while the general garbage collection
deals with cyclic structures.
But there's no magic: in particular in Java, Python and like languages you must
still remember to remove references installed in singletons and globals (e.g.
for event notifications), otherwise objects will still be referenced and thus
not garbage collected, causing a memory leak.
Cheers & hth.,
More information about the Python-list