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 is used of static keyword in java?

581


What are the types of inner classes (non-static nested class) used in java?

556


How to use string tokenizer class.

612


What is the purpose of using the java bean?

566


What is the file extension for java?

601






Can a constructor call another constructor?

558


How to provide security in java

1798


What is object data type?

558


What is array in java?

527


Explain the purpose of garbage collection in Java?

566


what is meant by Byte code concept in Java?

594


how to create multithreaded program? Explain different ways of using thread? : Java thread

523


What is the use of math abs in java?

541


What are the important features of Java 9 release?

526


Can long be null in java?

540