Let's simplify using public data member. Say I have (the code should
look same in C# and Java):
Class A
{
public B m_b;
}
Class B
{
public A m_a;
}
A a = new A();
B b = new B();
a.m_b = b;
b.m_a = a;
When a and b are not referenced by any other objects, a and b still
reference to each other. How does .NET know that a and b should be
garbage collected?
I raised the same question when JDK 1.0.x just came out, but don't
recall that I saw a concreate answer (maybe I missed it somehow). I
am pretty sure that Sun is handling it correctly in their current JVM.
If anybody knows how it works in JVM, please make your comments here
too. Thank you!
Regards,
Bill