Isolating a Reference

Isolating a Reference

its a diff way for the objects can become eligible for garbage collection even if they still have valid references!. We also know that the islands of isolation.

We have a code its very simple example for the call instance

public class Island {
Island a;
public static void main(String [] args) {
Island a2 = new Island();
Island a3 = new Island();
Island a4 = new Island();
a2.a = a3; // a2 refers to a3
a3.a = a4; // a3 refers to a4
a4.a = a2; // a4 refers to a2
a2 = null;
a3 = null;
a4 = null;
// do complicated, memory intensive stuff

When the code reaches // do complicated, the three Island objects have instance variables so that they refer to each other, but their links to the outside world have been nulled. These three objects are eligible for garbage collection.

Date:2014-03-09 00:00:00

Post Your Answers

User Email:

User Name:

Related scjp1.5 chap8 Links

scjp1.5 chap8 interview questions and answers for experienced and fresher