I have an application with two classes: A and B. Class A contains a reference to class B. Class destructors do some cleanup of resources, but they need to be called in the correct order, first the destructor A, and then the destructor B.
What happens is that one way or another, the destructor B is called first, and then destroys the destructor A, because it is trying to execute methods from the located object.
Is this GC behavior right? I expected the GC to detect that A has a reference to B, and then first call the destructor of A. Am I right?
Thank you comrades!
PD: In case of doubt regarding the destructor / finalizer / deletion, etc. that we have:
~A()
{
this.Dispose();
}
~B()
{
this.Dispose();
}