來自jlibs的RuntimeUtil.java中的以下片段可確保GC完成垃圾回收。因爲,它也使用System.gc(),我不明白他們如何保證它會發生100%的時間。Java:使用jlibs保證垃圾回收
以下是摘錄:
/**
* This method guarantees that garbage collection is
* done unlike <code>{@link System#gc()}</code>
*/
public static void gc(){
Object obj = new Object();
WeakReference ref = new WeakReference<Object>(obj);
obj = null;
while(ref.get()!=null)
System.gc();
}
確保所有終結器已運行? – 2012-06-27 20:06:48