My question is: When is an anonymous object swept by the garbage collector in Java?
The code is:
class Test extends Thread
{
Test(){}
public void run()
{
for(int i=0;i<4;i++)
System.out.println(this.getName()+"i="+i);
}
protected void finalize()
{
System.out.println("Finalized");
}
public static void main(String args[])
{
new Test().start();
}
}
From what I know about Java, any unreferenced object is swept by the GC. But there is no object reference here. Although the garbage collection process cannot be predetermined, but, still, when would the GC be "probably" done?