you give the object's reference null,and use System.gc();then the object you new will be delete.

解决方案 »

  1.   

    Object obj = new Object();
    .....
    obj = null;
    然后垃圾收集就把它清理掉了
      

  2.   

    垃圾回收器会自动清除对象释放内存
    如果手动可以用finalize(),但不提倡
      

  3.   

    system.gc()只是强制执行垃圾收集器
      

  4.   

    或者
    Object obj = new Object();
    Object obj2 = new Object();
    .....
    obj = obj2;
    这样obj就被回收了,但你最好别指望JVM有多聪明
      

  5.   

    system.gc 和 Runtime.gc() 执行的都是 notifyAll() 只是唤醒线程
    到底能不能回收 就不一定了  可以用 java plug-in4 回收  呵呵