Garbage Collection in Java
Garbage Collection When a Java object becomes unreachable to the program, then it is subjected to garbage collection. The main use of garbage collection is to identify and discard objects that are no longer needed by a program so that their resources can be reclaimed and reused. Advantages can be : Increase productivity as no need to worry about memory issues. Program integrity . Garbage collection is an important part of Java's security strategy. Java programmers are unable to accidentally crash the Java virtual machine by incorrectly freeing memory. Automatic Garbage Collection Automatic garbage collection is the process of looking at heap memory, identifying which objects are in use and which are not, and deleting the unused objects. An in use object, or a referenced object, means that some part of your program still maintains a pointer to that object. An unused object, or unreferenced object, is no longer referenced b...