In finalize()
method the statement written after the call to superclass finalize()
method will execute or not?
Asked
Active
Viewed 58 times
0

rtruszk
- 3,902
- 13
- 36
- 53

Mohd Saddam
- 1
- 1
-
Maybe this helps you: http://stackoverflow.com/questions/2506488/when-is-the-finalize-method-called-in-java – bish Jul 01 '15 at 06:16
-
What happens when you test it? Why wouldn't it execute? – JB Nizet Jul 01 '15 at 06:19
-
Unless, of course, an exception is thrown during finalization of the superclass. In that case, as [javadocs](http://docs.oracle.com/javase/7/docs/api/java/lang/Object.html#finalize()) stated, it just will be ignored. – Jul 01 '15 at 06:24
-
1...Why are you using `finalize`? You're not guaranteed that it will be executed. Ever. – Makoto Jul 01 '15 at 06:25
-
@Makoto I believe OP's informed about that, but trying to understand the behavior. – Jul 01 '15 at 06:27
-
First try it by your self. Just Don't raise your non-experimented queries. – Harshit Gupta Jul 01 '15 at 07:21
1 Answers
1
Not necessarily. An exception might be thrown. But you shouldn't have any code after that anyway. The correct form is:
protected void finalize() throws Throwable
{
try
{
// your code here ...
}
finally
{
super.finalize();
}
}

user207421
- 305,947
- 44
- 307
- 483