What is the difference between System.gc()
and Runtime.gc()
?
System.gc()和Runtime.gc()有什么区别?
6 个解决方案
#1
54
Both are same. System.gc()
is effectively equivalent to Runtime.gc()
. System.gc()
internally calls Runtime.gc()
.
两者都是一样的。 System.gc()实际上等同于Runtime.gc()。 System.gc()在内部调用Runtime.gc()。
The only difference is System.gc()
is a class method where as Runtime.gc()
is an instance method. So, System.gc()
is more convenient.
唯一的区别是System.gc()是一个类方法,其中Runtime.gc()是一个实例方法。所以,System.gc()更方便。
#2
15
From looking at the source code: System.gc()
is implemented as
从查看源代码:System.gc()实现为
Runtime.getRuntime().gc();
So it's just a convenience method.
所以这只是一种方便的方法。
#3
8
查看文档
System.gc()
is equivalent to Runtime.getRuntime().gc()
System.gc()等同于Runtime.getRuntime()。gc()
#4
2
Runtime.gc()
is a native method where as System.gc()
is non - native method which in turn calls the Runtime.gc()
Runtime.gc()是一种本机方法,其中System.gc()是非本机方法,而后者又调用Runtime.gc()
#5
1
System.gc():
System.gc()的:
1: It is a class method(static method).
1:这是一种类方法(静态方法)。
2: Non-Native method.(Code which doesn't directly interacts with Hardware and System Resources).
2:非本机方法(不直接与硬件和系统资源交互的代码)。
3: System.gc(), Internally calls Runtime.getRuntime().gc().
3:System.gc(),内部调用Runtime.getRuntime()。gc()。
Runtime.gc():
Runtime.gc():
1: Instance method.
1:实例方法。
2: Native method(A programming language which directly interacts with Hardware and System Resources.).
2:Native方法(一种直接与硬件和系统资源交互的编程语言)。
#6
0
In the runtime system the gc is instance method but in system method the gc is static .
在运行时系统中,gc是实例方法,但在系统方法中,gc是静态的。
because of this reason we prefer to use system.gc().
因为这个原因我们更喜欢使用system.gc()。
#1
54
Both are same. System.gc()
is effectively equivalent to Runtime.gc()
. System.gc()
internally calls Runtime.gc()
.
两者都是一样的。 System.gc()实际上等同于Runtime.gc()。 System.gc()在内部调用Runtime.gc()。
The only difference is System.gc()
is a class method where as Runtime.gc()
is an instance method. So, System.gc()
is more convenient.
唯一的区别是System.gc()是一个类方法,其中Runtime.gc()是一个实例方法。所以,System.gc()更方便。
#2
15
From looking at the source code: System.gc()
is implemented as
从查看源代码:System.gc()实现为
Runtime.getRuntime().gc();
So it's just a convenience method.
所以这只是一种方便的方法。
#3
8
查看文档
System.gc()
is equivalent to Runtime.getRuntime().gc()
System.gc()等同于Runtime.getRuntime()。gc()
#4
2
Runtime.gc()
is a native method where as System.gc()
is non - native method which in turn calls the Runtime.gc()
Runtime.gc()是一种本机方法,其中System.gc()是非本机方法,而后者又调用Runtime.gc()
#5
1
System.gc():
System.gc()的:
1: It is a class method(static method).
1:这是一种类方法(静态方法)。
2: Non-Native method.(Code which doesn't directly interacts with Hardware and System Resources).
2:非本机方法(不直接与硬件和系统资源交互的代码)。
3: System.gc(), Internally calls Runtime.getRuntime().gc().
3:System.gc(),内部调用Runtime.getRuntime()。gc()。
Runtime.gc():
Runtime.gc():
1: Instance method.
1:实例方法。
2: Native method(A programming language which directly interacts with Hardware and System Resources.).
2:Native方法(一种直接与硬件和系统资源交互的编程语言)。
#6
0
In the runtime system the gc is instance method but in system method the gc is static .
在运行时系统中,gc是实例方法,但在系统方法中,gc是静态的。
because of this reason we prefer to use system.gc().
因为这个原因我们更喜欢使用system.gc()。