This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Khalid: GC ? 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 "Khalid: GC ?" Watch "Khalid: GC ?" New topic
Author

Khalid: GC ?

Cathy Song
Ranch Hand

Joined: Aug 24, 2003
Posts: 270
"If object obj1 can access object obj2 which is eligible for garbage collection, then obj1 is also eligible for garbage collection".
I dont understand this. What is obj1 has a reachable reference, then obj2 wont be eligible anymore right?
Harwinder Bhatia
Ranch Hand

Joined: Oct 17, 2003
Posts: 150
The assumption here is obj2 is eligible for Garbage collection. This means that it cannot be referenced by any active part of the program. But it can be referenced by obj1. This means that obj1 cannot be referenced by any active part of the program either, which makes obj1 eligible for Garbage collection too.
If obj1 is reachable through a reference, then obj2 will be reachable too and hence no longer eligible for gc.
Maybe Marlene can explain it better.
Thanks
Harwinder
Marlene Miller
Ranch Hand

Joined: Mar 05, 2003
Posts: 1391
Harwinder, your explanation if very clear and logical.
Alton Hernandez
Ranch Hand

Joined: May 30, 2003
Posts: 443
In other words, a circular reference does not prevent an object from being GC'd.
 
GeeCON Prague 2014
 
subject: Khalid: GC ?