Garbage Collection and finalize() method
Garbage collection in Java is the automatic process by which the Java Virtual Machine (JVM) identifies and removes objects that are no longer reachable or in use by the program. The primary purpose of garbage collection is to reclaim memory occupied by objects that are no longer needed, freeing up resources and preventing memory leaks. …