How Does Garbage Collection in Java Work?
Java garbage collection is an automatic process. 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 or unreferenced object is no longer referenced by any part of your program.
So the memory used by an unreferenced object can be reclaimed. The programmer does not need to mark objects to be deleted explicitly. The garbage collection implementation lives in the JVM.
Does Garbage Collection Guarantee that a Program will not Run Out of Memory?
The work of Garbage collection in Java is to automate the process of deleting memory that’s no longer in use. But does that mean Java programs are free from memory limit overflow? Well in this article we will discuss it in brief, but first, let’s talk about the garbage collection in Java.