I need to know when the finalize() method is called in the JVM. I created a test class which writes into a file when the finalize() method is called by overriding it. It is not executed. Can anybody tell me the reason why it is not executing?
I need to know when the finalize() method is called in the JVM .
Share
In general it’s best not to rely on
finalize()to do any cleaning up etc.According to the Javadoc (which it would be worth reading), it is:
As Joachim pointed out, this may never happen in the life of a program if the object is always accessible.
Also, the garbage collector is not guaranteed to run at any specific time. In general, what I’m trying to say is
finalize()is probably not the best method to use in general unless there’s something specific you need it for.