Unloading
About the class unloading, the author in the singleton mode discussion article: Singleton mode and garbage collection article has been described, after the class is used, if the following situation, the class will be unloaded:
All instances of the class have been reclaimed, that is, no instances of the class exist in the Java heap.
The ClassLoader that loaded the class have been recycled.
The corresponding Java.lang.Class object of this class is not referenced anywhere, and cannot be accessed anywhere by reflection on the method of the class.
If all of the above three conditions are met, the JVM will unload the class at garbage collection time in the method area, and the class unloading process is simply emptying the class information in the method area, and the entire life cycle of the Java class is over.
Summarize
A friend of Java may be familiar with the life cycle of objects, which are basically created in the heap of the JVM, triggering class loading (loading, joining, initializing) before the object is created, and when class initialization is complete, instantiating class objects in the heap based on class information, initializing non-static variables, Non-static code and the default construction method are reclaimed by the JVM garbage collector when the object is used. After reading this article, we know that the life cycle of an object is only a case of using the active reference of the stage in the life cycle of the class (that is, instantiating the class object). The entire life cycle of a class is much longer than the life cycle of the object.
Java class life cycle, from loading, linking, initializing to unloading, when is the key to uninstall??