Home >Java >javaTutorial >How to determine virtual reference in java

How to determine virtual reference in java

王林
王林forward
2023-05-12 18:07:13974browse

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);

What collection classes are there in Java?

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!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete