Are there any details on whether or not an object is cleaned up using finalize()
if that object\'s constructor thew an exception.
When this method is ca
To demonstrate more clearly:
public class Test1 {
public static class LifeBoat extends RuntimeException
{
private Test1 passenger;
public Test1 getPassenger(){return passenger;}
public LifeBoat(Test1 passenger){this.passenger=passenger;}
}
Test1() {
super(); //once this is finished, there is an Object to GC per JLS 12.6.1.
throw new LifeBoat(this);
}
@Override
protected void finalize() throws Throwable {
System.out.println("finalized");
}
public static void main(String[] args) throws Exception {
try {
new Test1();
} catch (LifeBoat e) {
Test1 obj;
obj=e.getPassenger();
System.out.println(obj);
}
System.gc();
Thread.sleep(1000);
}
}
prints
java.lang.RuntimeException
at test.Test1.(Test1.java:13)
at test.Test1.main(Test1.java:24)
test.Test1@6dc8f3cd
finalized