Hi, I tried to run this piece of code:
public class Test{
public static void main(string arg[]){
Object obj = buildTest(3);
System.gc();
System.out.println("Existing");
}
public static test buildTest(int n){
Test t = null;
for (int i = 0; i < n; i++){
t = new Test(i);
}
return t;
}
string name;
public Test(int n){
name = "Number " + n;
}
public void finalize(){
System.out.print("finalize " + name);
}
}
The output I got was:
finalize Number 1
finalize Number 0
Existing
My questions is, why it does not print out "finalize Number 2"? If I pass 4 to buildTest in main(), it will not print "finalize Number 3" as well... Can anyone explain this? Is it because of the first line "Test t = null;" in buildTest()?
Any help is appreciated!!
[ June 09, 2006: Message edited by: Jay Cat ]
[ June 09, 2006: Message edited by: Jay Cat ]