Home >Java >javaTutorial >Detailed explanation of several common functions of Reference in Java
This article mainly introduces you to the relevant information about the multiple functions of Reference in Java. The article introduces it in detail through sample code, which has certain reference and learning value for everyone. Friends who need it will follow the editor. Study and study.
Preface
Several Reference functions in Java are also questions that are often asked during interviews. I used to remember them once and forget them again. Now that I have time, I might as well write a demo to test it out. Let’s take a look at the detailed introduction:
The specific code is as follows:
JVM Parameters: -Xmx10m -Xms5m -XX:+PrintGC
##SoftReference:
weakReference:
StrongReference:
Since strong is the JVM default, I won’t do it here, it will not be recycled at all until OOMPhantomReference:
VirtualThe following code, in essence, byte[] is still a strong reference. Output:##To summarize:
ThreadLocal< ;SoftReference
The above is the detailed content of Detailed explanation of several common functions of Reference in Java. For more information, please follow other related articles on the PHP Chinese website!