Java Reference Types
To reimburse different needs for references, Java provisioned different level of references type since 1.2
.
It actually meets some application requirement like caches.
Strong
The normal reference, unable to GC until no reference exists.
1 |
|
Soft
When memory about to overflow, good for saving memory when space sensitive.
1 |
|
Weak
Will be collected at next GC cycle. Designed for objects that have short life.
1 |
|
Phantom
weakest reference. As if there is no reference.
Phantom references are most often used for scheduling pre-mortem cleanup actions in a more flexible way than is possible with the Java finalization mechanism.
1 |
|
Java Reference Types
https://rug.al/2016/2016-04-04-java-reference-types/