Re: Copying GC and finalization

Chris Cheney <cjc1@cam.ac.uk>
28 Jul 2005 02:32:51 -0400

          From comp.compilers

Related articles
Copying GC and finalization der_julian@web.de (Julian Stecklina) (2005-07-26)
Re: Copying GC and finalization cjc1@cam.ac.uk (Chris Cheney) (2005-07-28)
Re: Copying GC and finalization liekweg@gmx.de (Florian Liekweg) (2005-07-28)
Re: Copying GC and finalization der_julian@web.de (Julian Stecklina) (2005-08-05)
Re: Copying GC and finalization eliotm@pacbell.net (Eliot Miranda) (2005-08-21)
Re: Copying GC and finalization der_julian@web.de (Julian Stecklina) (2005-08-24)
| List of all articles for this month |

From: Chris Cheney <cjc1@cam.ac.uk>
Newsgroups: comp.compilers
Date: 28 Jul 2005 02:32:51 -0400
Organization: University of Cambridge Computing Service
References: 05-07-105
Keywords: GC
Posted-Date: 28 Jul 2005 02:32:49 EDT

Julian Stecklina <der_julian@web.de> wrote in news:05-07-105@comp.compilers:
> I am looking for ways to implement finalization of and weak pointers
> to objects in a copying garbage collector. I am quite puzzled on how
> to implement this without losing the nice property of copying garbage
> collectors that there is nothing to do for objects that have become
> garbage.


Nothing to do except finalize them!


One (naive) way is to give all objects a hidden field ('hidden' meaning that
the garbage collector doesn't use it to find objects). I assume that the
type of the object is determinable when the object is accessed from the
hidden list.


1. When an object is created, chain it to a 'list of all current objects'
using this field.


2. When an object is found and copied by the garbage collector, unchain it
from the 'list of all current objects' and chain it to a 'temporary list'.


3. At the end of garbage collection, finalize all the objects remaining on
the 'list of all current objects' as these are the objects that have ceased
being current (= are garbage).


4. Empty the 'list of all current objects' and transfer the objects from the
'temporary list' to the 'list of all current objects'.


One will probably also wish to arrange that, if an object is finalized, it
is removed from the 'list of all current objects' (so that it is only ever
finalized once).


Whether the cost of this extra field is worthwhile clearly depends on the
particular application.


Now what about the weak pointers ...


HTH


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.