Today, during a phone interview, I was asked a question about WeakReference in Java. I only knew that the weak referenced object can be garbage collected by JVM, and nothing more. I did a little research, and realized that there are 4 types of references in Java:
- Strong Reference
- Soft Reference
- Weak Reference
- Phantom Reference
They are in the order from strong to weak references. 3 classes,
SoftReference,
WeakReference, and
PhantomReference are for the last 3 references. For strong reference, just use
new operator. Below is a great blog talking about all 4 references:
Understanding Weak References
No comments:
Post a Comment