What is the purpose of finalization?

Answer Posted / ranganathkini

Finalization is a facility provided by Java for classes who
use native resources to clean up before the objects are
garbage collected.

Since native resources or allocations are beyond the control
of Java's garbage collector, the responsibility of cleaning
up that native allocations falls on the object's
finalization code which shud ideally initiate quick clean up
operations and free any native memory it has allocated.

If finalization is not done, then the native resources wud
be left in the memory even after thier related Java
instances have been removed by the Java's GC. Hence it is an
invaluable feature.

But it needs to be used with caution as finalization
consumes more processing by Java

Is This Answer Correct ?    5 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are generic methods?

527


What are structs in java?

567


Can java program run without jre?

565


which class is the wait() method defined in? : Java thread

521


Explain the features of interfaces in java?

552






Why does abstract class have constructor?

552


What is balanced tree in java?

532


Which package has light weight components in java programming?

673


how to run ecllipse with jettyserver for windows environment using batch file

1490


What is the main function in java?

527


What things should be kept in mind while creating your own exceptions in java?

624


Explain different types of wrapper classes in java?

595


How many bytes is a string in java?

527


What is the significance of java packages?

609


Difference between arraylist and vector.

584