On Thursday, 02/06/2003 at 01:06ZE5B, abhay <[EMAIL PROTECTED]> wrote: > I have a > question here to ask.. If the 2 objects actually point to the same memory
> location > then how does the interpreter keep the track of the references attached to it ? > Doe it use any kind of 'reference counting mechanism' > > How will that object be garbage collected ? There are many GC algorithms, but I've never seen one that uses reference counting. Let me try to expound on the simplest synchronous GC "in a nutshell:" "Roots" are object references that are found in 1) selected global areas of the JVM, and 2) in the stacks of active threads. By definition, these roots are reachable, simply by virtue of their location, so the GC can always find them. Beginning with these reachable roots, GC follows object references from the roots "outward," marking all the objects it finds. When GC encounters an object that it has already marked, it can infer it's in a cycle and backtrack. Once the GC has marked everything that can be reached, everything *else* is garbage (almost -- there are issues with object "resurrection" by finalizers.) This is the simplest form of synchronous "stop the world" GC, and is really quite trivial. FWIW, no "industrial strength" GC stops here -- at least not anymore. Of course, there are many schemes to make a "better" GC, but they'd take far more than a paragraph to explain. HTH. -blair Blair Wyman -- iSeries JVM -- (507) 253-2891 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "It is a sobering thought that when Mozart was my age, he had been dead for two years." -- Tom Lehrer ____________________________________________________ To change your JDJList options, please visit: http://www.sys-con.com/java/list.cfm Be respectful! Clean up your posts before replying ____________________________________________________
