Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How many references are there in Java

2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "how many kinds of references there are in Java". The explanation in this article is simple and clear, easy to learn and understand. Please follow the ideas of Xiaobian and go deep into it slowly to study and learn "how many kinds of references there are in Java" together!

Strong reference: The common Object obj = new Object(); the garbage collector will never collect this object as long as the strong reference exists.

Soft references: Used to describe useful but unnecessary objects. These objects are included in the collection scope for secondary garbage collection before a memory leak occurs. If there is not enough memory for this collection, then a memory overflow will occur. Soft references can be used to implement memory-sensitive caching.

Weak references: Used to describe objects that are not essential, objects associated with weak references can only survive until the next garbage collection. When garbage collection occurs, objects associated with weak references are collected regardless of whether memory is sufficient.

Virtual reference: the weakest kind of reference relationship. Cannot get an object by virtual reference. Whether an object has a virtual reference or not has no effect on its lifecycle. Its sole purpose is to receive a system notification when garbage is collected. It differs from soft and weak references in that virtual references must be used in conjunction with a reference queue. When garbage collection prepares to reclaim an object and finds that the object has a virtual reference, it adds the virtual reference to the reference queue associated with it before reclaiming the object. If the program finds that a virtual reference has been added to the reference queue, it can take the necessary steps before the referenced object memory is reclaimed.

Soft reference, weak reference scenario principle analysis: memory sensitive cache.

Thank you for reading, the above is the content of "how many kinds of references in Java", after learning this article, I believe that everyone has a deeper understanding of how many kinds of references in Java, and the specific use needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report