I have three objects A, B and C. C is the child of both A and B. C has reference to A and B. A and B has reference to C. I understand that when the reference to C from both A and B gets deleted, C becomes garbage and will be collected by GC.
- Is my understanding correct?
- Should I set the Reference to A and B in C to NULL?
- If Yes, What is the benefit?
public class A { public C Cr { get; set; } } public class B { public C Cr { get; set; } } public class C { public A Ar { get; set; } public B Br { get; set; } } class Program { static void Main(string[] args) { var oa = new A(); var ob = new B(); var oc = new C(); oc.Ar = oa; oc.Br = ob; oa.Cr = oc; ob.Cr = oc; // Some operation oa.Cr = null; ob.Cr = null; //is the following code required? // if yes, what is the benefit? oc.Ar = null; oc.Br = null; } Thanks
Ram