Page 1 of 1

Garbage Collection

Posted: Sat Aug 05, 2017 6:21 am
by RRRRRR
Sir my question is->

class Beta{}
class Alpha
{
static Beta b1;
Beta b2;
}

class Tester
{
public static void main(String[] args)
{
Beta b1=new Beta();
Beta b2=new Beta();
Alpha a1=new Alpha();
Alpha a1=new Alpha();

a1.b1=b1;
a1.b2=b1;
a2.b2=b2;

a1=null; b1=null; b2=null;

//doStuff
}
}

When line doStuff is reached there is only 1 Object eligible for Garbage Collection. Why???

Re: Garbage Collection

Posted: Sat Aug 05, 2017 7:25 am
by admin
What do you think and why?

Re: Garbage Collection

Posted: Sat Aug 05, 2017 8:12 am
by RRRRRR
Sir, Since I am reading from Kathy Sierra , Bert bates and it is written that there is still a reference to the object referred to by a2 , and there is still a reference to the object referred to by a2.b2 .

We can still access other Beta object through the static variable a2.b1 -> bcz its static //Can't understand this

Re: Garbage Collection

Posted: Tue Aug 08, 2017 12:26 am
by admin
Did you contact the authors of the book?
What did they say?