Cast not your Perl before swine?

Levi Pearson levi at cold.org
Tue Dec 18 11:32:05 MST 2007


Michael L Torrie <torriem at chem.byu.edu> writes:
>
> I didn't mean to imply that Java used reference counting as a garbage
> collection scheme.  Only that the garbage collector does track reference
> counts in some fashion with some algorithm..

It tracks references, but not counts.

> C++ smart pointers simply check reference counts when the scope is
> destroyed, and call the destructor on the object they point to and free
> the memory, if the count hits zero.  I do not consider this technique to
> be "garbage collection" as most Java programmers would think of it.
> Rather it's just a method of managing resources in C++ that happens to
> be, in my opinion, very efficient from a programmer's point of view.

It may not be garbage collection as Java programmers consider it, but
garbage collection researchers generally include it as a garbage
collection algorithm.  It's a rather poor one, too.  It has poor space
usage (requires a refcount field for each object), significant
overhead (lots of twiddling of refcount fields all the time), and can
cause long pauses when a deallocation triggers a cascade of
deallocations of referenced objects.  Plain reference counting also
fails to free cyclic references.  It does have determinism going for
it, though, since objects are freed as soon as they are no longer
reachable.  This means that although objects are bigger by the size of
the refcount field, you never have more of them hanging around than
are strictly necessary, which may be a win if you have the right
number of objects / size of objects ratio.

                --Levi



More information about the PLUG mailing list