What is the difference between System.gc()
and Runtime.gc()
?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How can I create this custom Bottom Navigation on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
System.gc():
1: It is a class method(static method).
2: Non-Native method.(Code which doesn't directly interacts with Hardware and System Resources).
3: System.gc(), Internally calls Runtime.getRuntime().gc().
Runtime.gc():
1: Instance method.
2: Native method(A programming language which directly interacts with Hardware and System Resources.).
Both are same.
System.gc()
is effectively equivalent toRuntime.gc()
.System.gc()
internally callsRuntime.gc()
.The only difference is
System.gc()
is a class method where asRuntime.gc()
is an instance method. So,System.gc()
is more convenient.Runtime.gc()
is a native method where asSystem.gc()
is non - native method which in turn calls theRuntime.gc()
In the runtime system the gc is instance method but in system method the gc is static .
because of this reason we prefer to use system.gc().
From looking at the source code:
System.gc()
is implemented asSo it's just a convenience method.
See the docs
System.gc()
is equivalent toRuntime.getRuntime().gc()