Bookmark Topic Watch Topic
  • New Topic

how many objects are eligible for Garbage collection

 
Premak Rajan
Greenhorn
Posts: 18
  • 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
  • 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
  • Mark post as helpful
  • send pies
  • Report post to moderator
This problem was recently discussed here.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic