garbage collection in Java

Garbage Collector is to free heap memory by destroying unreachable objects.

Unreachable objects :

An object is said to be unreachable if it doesn’t contain any reference to it. Also note that objects which are part of island of isolation are also unreachable.

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.

// requesting JVM for running Garbage Collector
System.gc();

References:

http://www.geeksforgeeks.org/garbage-collection-java/

你可能感兴趣的:(garbage collection in Java)