Object finalize processing method, objectfinalize
We know that everything in java is an object. If you create a class, you can override the finalize method in the parent class. When will this method be called?
When the VM's garbage collector detects that this object is not reachable, that is to say, when this object can be recycled as garbage, the finalize () method of this object will be executed, by default, it is not processed. We can rewrite this method to release resources. This is generally not recommended because it costs a lot.
` @Override protected void finalize() throws Throwable { super.finalize(); }
This method also has a note, which can be determined to be called, but we can call it.
Runtime.getRuntime().runFinalization()
Gc is recommended to call this method, but it cannot be guaranteed to be called.
In fact, the finalize method does not have any logic in the object class and is only useful for rewriting. If you must use this method, you can explicitly specify the call.