This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
    Bookmark Topic Watch Topic
  • New Topic

how many objects are eligible for Garbage collection

 
Premak Rajan
Greenhorn
Posts: 18
  • 0
  • Mark post as helpful
  • send pies
  • Report post to moderator
I have doubt in this program

1. public class BettyAck{
2. public static void main(String argv[]){
3. BettyAck b =new BettyAck();
4. }
5. public BettyAck() {
6. Integer x = new Integer(10);
7. findOut(x);
8. Integer y = new Integer(99);
9. Integer z = y;
10. z = null;
11. findOut(y);
12. //here
13. }
14. public void findOut(Integer y){
15. y = null;
16.
17. }
18.}

my answer for this program is 3 objects are eligible for garbage collection.Is it correct or not?
Please anyone help me

with regards
prema
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • 0
  • Mark post as helpful
  • send pies
  • Report post to moderator
No object is eligible for GC.

This is the situation

a -> b -> object

When you make reference a point to null

a-> null
b -> object

So you can still get to the object with reference b
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • 0
  • Mark post as helpful
  • send pies
  • Report post to moderator
This problem was recently discussed here.
 
It is sorta covered in the JavaRanch Style Guide.
    Bookmark Topic Watch Topic
  • New Topic