Home >Java >javaTutorial >How to determine virtual reference in java
Judgement of virtual references
1. Virtual references must be used together with the reference queue (ReferenceQueue).
2. When the garbage collector is preparing to recycle an object, if it finds a virtual reference, it will add the virtual reference to the reference queue related to it before recycling the object's memory.
String str = new String("abc"); ReferenceQueue queue = new ReferenceQueue(); // 创建虚引用,要求必须与一个引用队列关联 PhantomReference pr = new PhantomReference(str, queue);
Collections in Java are mainly divided into four categories:
1. List: ordered, repeatable;
2. Queue: ordered and repeatable;
3. Set: non-repeatable;
4. Map: unordered, with unique keys and non-unique values.
The above is the detailed content of How to determine virtual reference in java. For more information, please follow other related articles on the PHP Chinese website!