Suppose I have a weak reference to a car which has an ordinary (strong) reference to an engine. No other references to the car or the engine exist. Can the engine be garbage collected?
Share
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.
Yes it can, that is exactly how weak references are designed to work. The weak reference is the root that your object has to the application, even though the object may have other strong references it is the root reference that matters and since the root reference is a weak reference the object will be a candidate for garbage collection.
For more information please see
WeakReferenceclass documentation:FYI, along with
WeakReference, Java offers two other subclasses ofReference:SoftReferenceandPhantomReference.