The Java run time calls that method whenever it is about to recycle an object of that class. Inside the finalize( ) method, specify those actions that must be performed before an object is destroyed.
The garbage collector runs periodically, checking for objects that are no longer referenced by any running state or indirectly through other referenced objects. Right before an asset is freed, the Java run time calls the finalize( ) method on the object.
The finalize( ) method has this general form:
protected void finalize( )
{
// finalization code here
}
Here, the keyword protected is a specifier that prevents access to finalize( ) by code defined
outside its class.
It is important to understand that finalize( ) is only called just prior to garbage collection.
1 Comments
Perfect 🙂
ReplyDelete