System.gc(),运行垃圾回收机制
System.runFinalization(),调用Finalize()释放资源

解决方案 »

  1.   

    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()
    runFinalization
    public static void runFinalization()
    Runs the finalization methods of any objects pending finalization. 
    Calling this method suggests that the Java Virtual Machine expend effort toward running the finalize methods of objects that have been found to be discarded but whose finalize methods have not yet been run. When control returns from the method call, the Java Virtual Machine has made a best effort to complete all outstanding finalizations. The call System.runFinalization() is effectively equivalent to the call:  Runtime.getRuntime().runFinalization()