I want to ask if garbage collector automatically deletes unused objects in a Java program or it should be manually done by assigning an object to null?
From here
In a programming language like C, allocating and deallocating memory is a manual process. In Java, process of deallocating memory is handled automatically by the garbage collector.
I'd suggest you reading the full article. You will have a good grasp of how GC works in Java. HTH.