You must know the type of java reference — a detailed explanation of the source code of WeakReference

Define @ h_ 403_ 1 @ WeakReference is a weak reference, which will not affect the collection of objects by the garbage collector and the life cycle of objects.

Description @ h_ 403_ 1 @ when the virtual machine decides to recycle a weakly reachable object at a certain point in time, it will automatically clear all weak references of the object, change the object to the finalizable state, and then put these newly cleared weak references into its registered reference queue. [the usage of WeakReference has been explained earlier. This article only makes some supplements to WeakReference from the perspective of source code.

Source code @ h_ 403_ 1@ public class WeakReference
extends Reference

{

WeakHashMap@H_403_1 @When it comes to WeakReference, we can't help but talk about weakhashmap. The usage of this map is basically the same as HashMap. Its feature is to use weak references as keys, which makes it have a very important feature. It can automatically clear itself, so it doesn't need to release reference instances manually like softreference before. There will be a detailed introduction to weakhashmap in another article, so I won't say more here. be like... There's nothing to say. In the previous article on weak quotation, we have basically finished.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>