Re: Promptness of collection

Richard Jones <[email protected]> Wed, 13 Mar 2013 10:42:52 +0000
Newsgroups gmane.comp.programming.garbage-collection.general
Message-ID <[email protected]>
On 13 Mar 2013, at 09:20, [email protected] wrote:

On 12/3/13 11:08 AM, Eliot Moss wrote:

>=20
> On 3/12/2013 10:45 AM, Jon Harrop wrote:
>=20
>> 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.
>=20
> 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.

Well, let's see if there's a way that this could be true. Compare a simple =
two-generation collector with a fixed size nursery with a simple deferred r=
eference counter. Suppose there are no cycles, no finalisation, etc. Note t=
hat DRC will not free all garbage immediately but periodically stops the wo=
rld and processes the roots. Suppose the volume of live objects at the time=
 of a collection is  "livesize".  In these cases, the generational collecto=
r will reclaim garbage in the nursery after NURSERY_SIZE allocation whereas=
 the DRC collector will reclaim all garbage after (HEAP_SIZE - livesize) al=
location. It's entirely likely that NURSERY_SIZE < HEAP_SIZE - livesize so =
the generational collector might collect *some* but not all garbage more pr=
omptly than the DRC collector. But I think this is not a particularly profi=
table avenue to explore...

More importantly, note also that even an immediate (i.e. non deferred) refe=
rence counter cannot reclaim objects as soon as they are no longer referenc=
ed as finalisation must be asynchronous (see Hans Boehm's POPL03 paper "Des=
tructors, finalizers and synchronization", http://dl.acm.org/citation.cfm?d=
oid=3D604131.604153.

Richard=