Yes using System.gc() method
When the garbage collector invokes it cleans the orphan instances and call the finalizer method automatically before cleanup work.
Example
import static java.lang.System.out;
class Test
{
public void finalize()
{
out.println("Bye Bye...");
}
public static void main(String[] args)
{
Test t=new Test();
t=null; //orphan instance
System.gc();
}
}
Comments
Post a Comment