In java, object destruction is taken care by the Garbage Collector module and the objects which do not have any references to them are eligible for garbage collection. Garbage Collector is capable to identify this type of objects.
Island of Isolation:
- Object 1 references Object 2 and Object 2 references Object 1. Neither Object 1 nor Object 2 is referenced by any other object. That’s an island of isolation.
- Basically, an island of isolation is a group of objects that reference each other but they are not referenced by any active object in the application. Strictly speaking, even a single unreferenced object is an island of isolation too.
Finalize method called Finalize method called
Before destructing an object, Garbage Collector calls finalize method at most one time on that object.
The reason finalize method called two times in above example because two objects are eligible for garbage collection.This is because we don’t have any external references to t1 and t2 objects after executing
All we have is only internal references(which is in instance variable i of class Test) to them of each other. There is no way we can call instance variable of both objects. So, none of the objects can be called again.
Now, both the objects are eligible for garbage collection as there is no way we can call them. This is popularly known as Island of Isolation.
This article is contributed by Gaurav Miglani. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
- Java.util.BitSet class methods in Java with Examples | Set 2
- Java.Lang.Float class in Java
- Java.io.BufferedInputStream class in Java
- Java.io.ObjectInputStream Class in Java | Set 1
- Java.util.BitSet class in Java with Examples | Set 1
- Java.io.File Class in Java
- Java.io.BufferedWriter class methods in Java
- Java.io.DataOutputStream in Java
- Java.io.StreamTokenizer Class in Java | Set 1
- Java.io.InputStream Class in Java
- Java.io.SequenceInputStream in Java
- Java.io.StreamTokenizer Class in Java | Set 2
- Java.io.Console class in Java
- Java.io.FilterOutputStream Class in Java
- Java.io.StringWriter class in Java
- Java.io.CharArrayReader Class in Java
- Java.io.FileInputStream Class in Java
- Java.io.CharArrayWriter class in Java | Set 1
- Java.io.CharArrayWriter class in Java | Set 2
- Java.io.DataInputStream class in Java | Set 1