[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
circular references?
Jonathan Rochkind wrote:
>> Repeat after me: "garbage collection is not reference counting". Garbage
>> collection focuses on object reachability, not how many references an
>> object has. A subtle distinction, but it makes all the difference.
>
> I understand that, but of course GC relies on a sort of reference
> counting, internal to the JDK and unfortunately unavailable to the
> programmer (it would be nice if it were accesible via reflection
> interfaces of some kind, but it's not). "Reachability" is defined in
> terms of how many references an object has (and what types they are:
> strong, weak, etc). How else would you define it?
JDK has no internal reference counting. Most GCs are either mark&sweep
or copying collectors. To find out whether an object is "reachable", the
GC walks over all objects starting at the root-set (which is the stack
[simplified]) and "marks" or "copies" them. All objects which are
neither marked nor copied are unreachable and therefore
deallocated/finalized.
In other words, "reachability" is just a flag, not an RC like you may
know from Foundation. The GC doesn't care on how many references there
are, but only whether there is a single one. Of course the mark process
could calculate the number of references to an object, but this would be
a pretty expensive operation !
Greetings,
Helge
ps: there are also GCs based on RC (eg the one in POC), but they usually
cannot resolve circular references ! You need a tracing collector to do
fix this.
--
__________________________________________________________________
Helge Hess Email: helge.hess@xxxxxxxxxx
SKYRIX Software AG Tel: +49-391-6623-0
Universitaetsplatz 12 Fax: +49-391-6623-599
39104 Magdeburg, Germany Internet: http://www.skyrix.com
__________________________________________________________________
SKYRiX Groupware. We organize teams !
__________________________________________________________________