Grokking Java Interview Questions
0% completed
Strong, Soft, Weak, and Phantom References
| Reference | Class | Can get() return the object? | The collector may free the object |
|---|---|---|---|
| Strong | None, an ordinary variable or field | Not needed | Never, while the reference is reachable |
| Soft | SoftReference | Yes, until it is cleared | When memory is needed |
| Weak | WeakReference | Yes, until it is cleared | At any collection |
| Phantom | PhantomReference | Never | At any collection |
The last column assumes that no stronger reference leads to the object. The three classes are in the package `java.lang.ref
.....
.....
.....
Like the course? Get enrolled and start learning!
Reading Progress
0%