"Joel VanderWerf" <vjoel / PATH.Berkeley.EDU> wrote in message
news:3C77FE87.8E618042 / path.berkeley.edu...
> Sean O'Dell wrote:
> > I guess I don't understand how GC works.  I assumed that it walks the
entire
> > list of living objects and gets rid of the ones no longer in use.  It
seems
> > that it would be easier to just check one object rather than every
object in
> > the list.
>
> GC starts with objects that are known to be reachable, like the values
> of global vars, constants, stuff on the stack. Then it walks through the
> objects that their variables reference, and so on, recursively.
>
> You have to traverse all reachable objects before you know if any
> particular object is garbage. How would you check just one object,
> unless you were using ref counting?
>

one way to do it is to add a couple of reference bit, essentially a refcount
which only works with 3 value: 0 references => destroy
    1 reference => keep
    more references => GC
usually the idea is that allows for quick destruction of objects which would
have
been allocated on the stack in C, C++ when they go out of scope. The idea is
that
the 2 necessary bits can usually come out of a flag part of an object header
without
hadding any per object memory overhead just by using unused bits (most
interpreters have
an int or long there and don't use all the possible values).
Benoit