You can overwrite the method finalize() of this class,then
call method:System.gc().if a object of this class has no any reference refering to it,then
,this object will be collected as a garbage by garbage collector.There is
an example below:
public class TestFinalize
{public void finalize()
{System.out.println("call finalize()");
}
public static void main(String[] args)
{/*creat a object without reference,so it's a garbage.
*/
new TestFinalize();
/*force to execute garbage collection,so the garbage above will be collected.When a garbage object be collected,the method finalize() of this class must can be executed automatically before.
*/
System.gc();
}
}
The answer can be find in chapter 4 of <<thinking in java>>.
I'm learning java and english.So please correct my language error when correcting my program error.welcome exchanging.