System.gc () for the garbage collector, calling the garbage collector will reclaim unused
System.gc () were recovered criteria:
Recycling object is not pointing to any variable up
JDK implementation
public static void gc() { Runtime.getRuntime().gc(); }
Call the gc method of class Runtime
public native void gc();
Runtime class gc method is a native method, only the code into the JVM to see its true realization
JVM implementation
JNIEXPORT void JNICALL Java_java_lang_Runtime_gc(JNIEnv *env, jobject this) { JVM_GC(); }
Direct call JVM_GC () method, implemented in the jvm.cpp
This look down, you will find, System.gc () triggers a Full GC
Full GC takes longer, a greater impact on the application, generally do not recommend the use of System.gc ()
In the case of using an external heap memory, the external memory heap if not enough space application, jdk will trigger a System.gc (), to recover
Suggest:
Do not use a function gc
Keep the code robust (unused variable is set to null), so that virtual machines to manage memory