[comp.lang.eiffel] reference counting vs. GC again

ttwang@polyslo.CalPoly.EDU (Thomas Wang) (09/03/89)

I have received several letters saying garbage collection is indeed
superior to reference counting.

I am still reading "Object-oriented Software Construction".  I just found
another issue dealing with reference counting versus garbage collection.

On page 88, there is an example:
-- Assume that here b is not void and b.x is true
a := b; -- a now points to b's object
a.set_x_false
-- Then here b.x is false

One solution to this problem is for function set_x_false() to know if
'a' is the sole user of the object.  If the object is shared by more than
one reference, then 'a' must be assigned a clone object first.  This
solution requires set_x_false() to know the reference count.  If we must
maintain a reference count in the first place, why not use reference counting
for this class?

In any case, the reference count can be put into good use even in a
garbage collection system.  We can give an object with high reference count
a longer grace period (I.E. make it a tenured object for a while).

I hope C++ can have an automatic memory management system, but I am not
holding my breath.

 -Thomas Wang ("Ole wa onna da!!!"
                  - from Urusei Yatsura)

                                                     ttwang@polyslo.calpoly.edu