I am worried about garbage collection when two objects refer to each other ...
public class A
{ public readonly B _b;
public A()
{ _b = new B(this);
}
}
public class B
{ public readonly A _a;
public B(A objA)
{ _a = objA;
}
}
In this case, the third class may refer to A...
public class Foo
{ public A _a = new A();
public void Bar()
{ _a = new A();
}
}
Typically, the garbage collector has objects that no longer have active links. But in this case, objects A and B never lose all of their active links, since they always refer to each other.
When an object Fooreplaces the current A(s B) with new A(s B), will the garbage collector be able to clear the old A(s B) without starting an infinite loop with circular object references?
, ASP.NET. - , , .
:
& ; < - - .
& ; < - - .
.NET ?