Java class life cycle, from loading, linking, initializing to unloading, when is the key to uninstall??

Source: Internet
Author: User

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??

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.