Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Circular Object Reference

800457Oct 4 2007 — edited Oct 4 2007
If I have two objects, each with a reference to the other, will the garbage collector ever remove them if nothing else is referencing either one? In other words, if the only thing referencing object A is object B and the only thing referencing object B is object A will the garbage collector realize that these two objects can be removed?

A google search seems to indicate that it will but given that a static variable referencing an object instance (such as the Singleton pattern) will prevent the object from being removed I'm not so sure this is true.

I would try to create a test case to see for myself if this works but don't know how to begin. I guess I don't fully understand the GC process.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 1 2007
Added on Oct 4 2007
1 comment
84 views