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.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.