The best thing about java garbage collection is that it's automatic. You don't have to do anything, unless you want and need to control and tune it. When the JVM will decide it's time to start reclaiming the space on the heap and throwing away unused objects it will just start the garbage collection process.
If you want to force the garbage collection you can use the System object from java.lang package and it's gc() method or Runtime.getRuntime().gc() method.
Note - It's considered a bad practice of calling garbage collection explicitly instead we should tune the work of garbage collector.
Edit your Comment