[2009] in java-interest

home help back first fref pref prev next nref lref last post

Re: Question on circular linked lists

daemon@ATHENA.MIT.EDU (Larry Reu)
Thu Sep 21 17:06:42 1995

Date: Thu, 21 Sep 1995 11:15:07 -0700 (PDT)
From: Larry Reu <larryr@CyberGate.COM>
To: Edmund Burnette <sasebb@unx.sas.com>
cc: java-interest@java.sun.com
In-Reply-To: <199509201930.AA14219@zen.unx.sas.com>



On Wed, 20 Sep 1995, Edmund Burnette wrote:

> Suppose that you have a circularly linked list. Wouldn't it be
> possible to orphan this memory and have a memory leak,
> since nulling the master pointer wouldn't decrement the use
> count to zero, and it would seem impractical for the system
> to check for loops in the reference chains.
> 
I believe the method of GC which Java does not rely on ref counts.
If you have a list (cirular or not) and there is no existing root
pointing to this list then the list (or rather the memory which
happens to contain the list) is unreachable therefore it is collected.

roots are globals/statics and any local (stack based) vars in all
of the current frames.  i.e. in a procedural lang like C you can
walk the stack backward from the current frame back to main() (or
whoever called main, etc) looking for items which "look" like 
pointers into your heap space; you add thease to you known list
of globals and statics and this is your "set of roots" now any
heap memory "reached" from these roots is considered good all
other heap blocks are now considered "free".  Of course in the worst
case the GC will mistake some stack item as being a pointer when 
in fact it was just some value which looked like a pointer.  Thus,
some memory may be incorrectly kept -- however there is a faier 
chance that on the next GC this memory will be collected.

this is Conservative GC in a nut-shell.  I'm sure there are person's
out there which can explain it better then I.

............larry
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post