On Tue, 27 Nov 2001, mark hahn wrote:

> > Circular references will cause the object to stay around indefinitely
>
> I was thinking of the reference counting as being totally seperate from gc.
> So ref counting would have no effect one way or the other as to how long
> objects "stay around".  The only effect of the ref counting would be to call
> the special method which is not the gc finalizer.  I don't have a name for
> this method yet, maybe "pre-finalizer"?

Consider the situation in which object A holds a reference to object B,
and object B holds a reference to object A, but nobody holds a reference
to either object A nor object B.

In this case, both objects are useless; nobody can call methods on them,
because nobody has a reference to them.  However, their reference count
will never drop to zero, and the finalize method will never get called.

What's worse is that if reference counting is not properly implemented,
then these objects might be garbage-collected, even though their reference
count is nonzero (because in the mark phase of GC, the objects will not be
marked, since no one has a reference to them).

> > any object that holds a reference to a reference-counted object must
> itself be reference-counted
>
> I don't see why.  Is this another instance where you are thinking of the ref
> counting being part of gc?

Let foo be reference counted, and let bar be non-refcounted.

Let bar obtain a reference to foo upon initialization, and release the
reference upon finalization.

foo's reference count will not drop to zero until a) no object has a
reference to bar, and b) the mark/sweep GC has started.

Paul