Java automatically calls garbage collector, then why we need manual calls for garbage collection? When should use System.gc()
There is no need to call System.gc() or Runtime.getRuntime().gc(). The JVM internally controls garbage collection if it finds that it is running out of memory.
System.gc()
Runtime.getRuntime().gc()