Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java references

Is there any way to find all references to an object (in Java)?

I have a cache of objects, and would like to periodically scan it to see if removing the object will cause it to be destroyed.


1 Answers

You might want to take a look at different reference types Java provides: strong, soft, weak, and phantom.

For cache you would normally wrap a reference into WeakReference or SoftReference and let the object be collected once there are no more strong references left.

like image 100
Vlad Gudim Avatar answered May 18 '26 07:05

Vlad Gudim



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!