Is finalize() method really recommended in a java program? Justify

Showing Answers 1 - 1 of 1 Answers


Using finalize() method in java is not a recommended solution to release the system resources used by an object. 

The finalize() method will be called before deleting an object. An object in java will be deleted only by a garbage collector. The execution of garbage collector depends upon the JVM implementation. It is not guaranteed that when a garbage collector will be invoked and so its not a good idea to rely on this method.

Instead of this method using finally block to free these resources is more reliable. Because a finally block always gets executed.

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions