Re: Promptness of collection

Eliot Moss <[email protected]> Tue, 12 Mar 2013 11:08:06 -0400
Newsgroups gmane.comp.programming.garbage-collection.general
Message-ID <[email protected]>
On 3/12/2013 10:45 AM, Jon Harrop wrote:

> My impression is that even scope-based reference
> counting (e.g. C++ smart pointers) produces more floating garbage than a
> simple generational mark-sweep collector.

How could this be? A mark-sweep collector cannot reclaim
an object while it is referenced, and (unless you have a
lot of smarts in an optimizing compiler or something) the
reference persists until the scope is exited.  Presumably
when reference counting, an explicit assignment of null
will decrement the reference count immediately.

Of course you typical smart-pointers style ref counting
algorithms do not reclaim cycles, or at least not right
away, so that is one place a tracing collector can win,
but it seems I am really missing the boat if your impression
is correct.

It is true that detailed reference counting as you go
tends to have a high overhead, and that referred ref
counting is where the scheme becomes more competitive.

There are existing results that indicate that tracing
collection can be at least as efficient as reference
counting (in terms of time), but that it tends to require
somewhat more space than hand crafted malloc-free.  Prompt
ref counting might need even less space (malloc-free requires
a strong guarantee at the free that the object really is
becoming unreachable, or at least dead (won't be touched
again -- a subtly different concept)) but will require
more overhead than malloc-free.  But perhaps I digress ...

Maybe you need to explain better how it is you think a
tracing collector will reclaim sooner than a smart pointers
ref counter ...

Regards -- Eliot Moss