Thers is no way to force GC to run, right? I believe the GC is called when JVM is running out of memory.
【在 m*m 的大作中提到】 : java执行GC是不确定的, 除非force GC.
z*g
7 楼
You can't force GC.
【在 m*m 的大作中提到】 : java执行GC是不确定的, 除非force GC.
o*v
8 楼
System.gc();
【在 z****g 的大作中提到】 : You can't force GC.
z*g
9 楼
This only suggest garbage collect to run, not really forcing it. read your java book.
【在 o**v 的大作中提到】 : System.gc();
o*v
10 楼
gc public static void gc()Runs the garbage collector. Calling the gc method suggests that the Java Virtual Machine expend effort toward recycling unused objects in order to make the memory they currently occupy available for quick reuse. When control returns from the method call, the Java Virtual Machine has made a best effort to reclaim space from all discarded objects. The call System.gc() is effectively equivalent to the call: Runtime.getRuntime().gc() See Also: Runtime.gc()
【在 z****g 的大作中提到】 : This only suggest garbage collect to run, not really forcing it. : read your java book.
z*e
11 楼
no, even if you call GC explicitly, there is no guarantee JVM will do it immediately. a typical question for scjp test.
【在 f********h 的大作中提到】 : jvm will decide when to use GC,and you : can also call GC explicitly. : check javadoc of GC
g*g
12 楼
What actually implemented in background is that once you call GC, the priority of GC thread increases. There is no promise highest priority thread will be executed immediately, as they might be equal peers.
【在 z***e 的大作中提到】 : no, even if you call GC explicitly, there is no guarantee JVM will do it : immediately. : a typical question for scjp test.
c*g
13 楼
about java GC, you can suggest, but can't demand. JVM has the final say about when to do it.