Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strong references within weak references

in Java, are strong references accessible from weakly reachable objects are considered as strong references?

Example :

  • I can access X by a weak reference.
  • I can access Y by a weak reference.
  • I can access X by a pointer from Y.
  • I can access Y by a pointer from X.

If there is no other pointer on X and Y, I would expect them to get garbage-collected. Am I wrong?

like image 710
Béatrice Cassistat Avatar asked Oct 30 '25 19:10

Béatrice Cassistat


1 Answers

Even though the term strong reference is used, perhaps it is better to think in terms of reach-ability.

That is, if the object is strongly reachable from a root object it is not eligibility for reclamation -- otherwise, it is. A strong reference to an object only referenced through a weak reference is not strongly reachable. However, the strong reference is still a strong reference.

Happy coding.


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!