This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Circular references

 
Samith Nambiar
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may want to have a look at this article about garbage collection:
Reference Objects and Garbage Collection
HIH
 
Pres Brawner
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yup i had a look at that ... it helped ... thanks
/SAmith
 
Rob Ross
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Valentin ,
thanks for the good link! I had always wanted to learn about weak references, and now I learned something.
Thanks,
Rob
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic