What is the difference between System.gc() and Runtime.gc()?
Both are same System.gc() is effectively equivalent to Runtime.gc()
System.gc() internally calls Runtime.gc().
The only difference is :
System.gc() is a class (static) method where as Runtime.gc() is an instance method. So, System.gc() is more convenient.
System.gc()
public final class System extends Object{
public static void gc(){
.
.
Runtime.getRuntime().gc();
}
.
.
}
Runtime.gc()
public class Runtime extends Object{
public void gc(){
// ...
}
.
.
.
}