aspose file tools *
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Circular references Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Circular references" Watch "Circular references" New topic
Author

Circular references

Samith Nambiar
Ranch Hand

Joined: Mar 14, 2001
Posts: 147

is it right that in such a situation the two object can only be eligible for garbage collection when both the references are set to null?
from the veiwpoint of the exam is there anything else i need to know about circular references and garbage collection.
Shivaji Marathe
Ranch Hand

Joined: Jan 11, 2002
Posts: 203
The garbage colletor in JVM does resolve circular references.
Let's say Obj1 and Obj2 can not be accessed from any other references, but they can reference each other, then the garbage collector will release the memory occupied by those objects.
Hope this helps
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
You may want to have a look at this article about garbage collection:
Reference Objects and Garbage Collection
HIH


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Pres Brawner
Ranch Hand

Joined: Jan 18, 2001
Posts: 92
It would be helpful if we were to know why we should look at this reference. Is the current explanation not sufficient?
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Pres,
it never hurts to know more than expected. See that as a sort of computer culture or something.
Sure the explanation is sufficient, but it is up to you if you want to look under the hood or not.
Nothing is mandatory, I gave the link, if you think you don't need it, then don't read it. If you think you got the meaning of circular references and garbage collection with the answers you read then fine, otherwise, take a look at hte link.
Pres Brawner
Ranch Hand

Joined: Jan 18, 2001
Posts: 92
Valentin,
I think you're missing the point. Look carefully at your initial post. It can be viewed from two perspectives.
One: If you know the answer already provided is correct and want additional information, see this link.
Two: The original answer was incorrect. For the correct answer, follow this link.
I know you know what you mean. Please just let the rest of us in on it.
Thanks.
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Whatever,...
I didn't mean to be misleading... If it is how you feel, then I apologize. It's just that sometimes I don't take enough time to answer a question and the quality of my answer is not that good.
Usually when an answer is not sufficient, not accurate or wrong, I say it loud, oh yeah, and I give my explanation. Otherwise if I just let go, it means that the answer is correct (according to me) but, here you go, here is some more information about the question... So my intention was the first perspective you gave, but how could you know, you're not a mind reader
Samith Nambiar
Ranch Hand

Joined: Mar 14, 2001
Posts: 147
Originally posted by Shivaji Marathe:
The garbage colletor in JVM does resolve circular references.
Let's say Obj1 and Obj2 can not be accessed from any other references, but they can reference each other, then the garbage collector will release the memory occupied by those objects.

is this absolutely right ??? ... if so i dont seem to understand how the GC will release the memory when infact there is a reference for each of the two objects
thanx for the link Valentin
/SAmith
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1873
hi samith,
there r ways to get rid of circular ref problem for GC. one way i know is something called "train algorithm" but i have forgotten how exactly it works. you can refer to
Artima.com
which can give u some more idea about garbage collection.
regards
maulin.
Shivaji Marathe
Ranch Hand

Joined: Jan 11, 2002
Posts: 203
Samith :
The article that valentin provided a link to, inlcudes a very nice diagram representing how objects that reference each other, but can not be referenced from any other objects are eligible for garbage collection.
HTH
Samith Nambiar
Ranch Hand

Joined: Mar 14, 2001
Posts: 147
yup i had a look at that ... it helped ... thanks
/SAmith
Rob Ross
Bartender

Joined: Jan 07, 2002
Posts: 2205
Valentin ,
thanks for the good link! I had always wanted to learn about weak references, and now I learned something.
Thanks,
Rob


Rob
SCJP 1.4
 
 
subject: Circular references