The Finalize () method in the "Go" Java
This morning, see thinking in Java, "the fourth chapter initializes and clears". "Clear: End and garbage collection" When you see this thing.
Used to clean the drip ...
Of course, this method comes from Java.lang.Object
Rewrite of Finalize () method
Permissions (access) need to be protected or public, not private
The Finalize () method does not require a display call and is automatically called when garbage collection (GC) occurs.
According to my test, the garbage collection Method (System.GC ()) needs to be shown, and the presence of an anonymous object that has not been destroyed by new is required (calling other languages is not considered), and the Finalizze () method is called
Eg:
public class F {public static void Main (String args[]) { new F (); int a[] = new Int[3]; F f= new F (); System.GC (); } public void Finalize () throws throwable{ //super.finalize (); System.out.println ("Finalize method was called!");} }
In the above code, a new anonymous object, an integer array, and an instance object F, respectively, are called by the Finalize method only when an anonymous object is created and the System.GC () method is called by the test result.
The Finalize () method in Java