Java does have automatic garbage collection.
However there are some things you need to do. Java only GCs those objects in the heap that have no reference. What you do is assign null value the variable you no longer require and want the memory in heap to be freed. If you do not assign null to the variables, the objects in the heap will have a reference and will occupy the memory space even if you do not need them anymore.