• Post Reply Bookmark Topic Watch Topic
  • New Topic

cyclic reference in gc  RSS feed

 
Vasim Patel
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wanted to know how cyclic references are resolved during garbage collection.
Lets we have a circular linked list
class A has reference to B
class B has reference to C
class C has reference to A

If I make A null, and assume it is garbage collected, will C and B be GCed as well?
Is there any good doc which explains garbage collection in case of cyclic references
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is entirely up to JVM implementation, so you'd have to consult the docs for a particular JVM.

Cyclical references would be a problem if GC's used reference counting as their algorithm to identify unused object. However, I don't think any do - reference counting has big performance issues, as well as the possibility of deadlock you've noticed.
 
Vasim Patel
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paul

Are you aware of any link to such documentation?

Also, I wanted to know more about the various algorithms that JVM used for GC like mark and sweep. Are there any good docs? or any books worth buying?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sun has docs - have a hunt around their site. I don't know of any books - this is quite an advanced topic though. I can't imagine many programmers will need this sort of info for their day-to-day activities, so I don't know how well covered by third party books it will be.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!