February 5, 2011

Garbage collection in Java: Islands of Isolation

"Islands of Isolation" refers to objects with circular references to each other but with no reference to any of the objects from a Java program.

The following program creates an Island of Isolation of 3 objects.

public class Test {
   private Test next;

   public static void main(String[] args) {

      Test t1 = new Test();
      Test t2 = new Test();
      Test t3 = new Test();

      t1.next = t2;
      t2.next = t3;
      t3.next = t1;

      t1 = null;
   } 
}

No comments:

Post a Comment