Home > Java > javaTutorial > What is the difference between weak reference and soft reference in java

What is the difference between weak reference and soft reference in java

PHPz
Release: 2023-05-03 23:46:05
forward
1189 people have browsed it

Difference

1. Only objects with weak references have a shorter life cycle.

2. During the process of scanning the storage area under the jurisdiction of the garbage collector thread, if an object with only weak references is found, the storage will be recycled regardless of whether the current storage space is sufficient. However, the garbage collector is a low-priority thread and will not necessarily find objects with only weak references quickly.

Example

    String str = new String("abc");
    WeakReference<String> weakReference = new WeakReference<>(str);
    str = null;
Copy after login

Note: If the object is used occasionally (rarely) and you want to obtain it at any time during use, but you don’t want to affect the garbage collection of the object, then WeakReference should be used to remember objects.

What are the basic data types of java

The basic data types of Java are divided into:

1. Integer type, used to represent the data type of integer.

2. Floating point type, a data type used to represent decimals.

3. Character type. The keyword of character type is "char".

4. Boolean type is the basic data type that represents logical values.

The above is the detailed content of What is the difference between weak reference and soft reference in java. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Install JAVA
From 1970-01-01 08:00:00
0
0
0
Unable to install java
From 1970-01-01 08:00:00
0
0
0
Can java be used as the backend of the web?
From 1970-01-01 08:00:00
0
0
0
Is this in Java language?
From 1970-01-01 08:00:00
0
0
0
Help: JAVA encrypted data PHP decryption
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template