70 likes | 80 Views
https://firstcode.school/island-of-isolation-in-java/
E N D
Island of Isolation in Java with Example F I R S T C O D E . S C H O O L
Island of isolation in Java: The Garbage Collector module does the destruction of objects. The objects that do not have any sort of references to them are eligible for garbage gathering. We use a Java garbage collector to identify such objects. In a situation when Object 1 references Object 2 and Object 2 references Object 1, but neither Object 1 nor Object 2 is referenced by another object, this is an island of confinement. Now, collecting all the items that reference each other but are not referenced by another dynamic object in the application is termed an island of isolation.
Program explanation Before object destruction, the garbage collector invoke the finalize methods for one last time on the instance. In the given example, we call the finalize method twice as the count of objects qualifiable for garbage collection is two. This is due to absence of external forces to t1 and t2 after executing t2 = null. Only internal references to these values are present. In addition to it, we can call no other objects as there is no likelihood to call an instance variable of both the objects.
Till t2.i = t1: Both the objects have external references t1 and t2.
t1 = null: Both the objects can be reached via t2.i and t2 respectively.
Here, both the objects are eligible for garbage collection as there is no way to call them. This is the Island of isolation.
Conclusion N O W , Y O U M I G H T B E C L E A R A B O U T T H E I S L A N D O F I S O L A T I O N I N J A V A A N D G A R B A G E C O L L E C T I O N . Y O U A L S O G O T T O L E A R N H O W T O M A K E A N O B J E C T C O L L E C T I O N . T R Y T H E S A M P L E P R O G R A M T O F I N D T H E W O R K I N G O F T H I S C O N C E P T . H O W T O U S E I T I N T H E E L I G I B L E F O R G A R B A G E F I R S T C O D E . S C H O O L