M
mupp
I am wondering if someone could please explain the behaviour observed
in the following example:
class Contained
{
~Contained ()
{
}
}
class Container
{
Contained m_oContained;
public Container ()
{
m_oContained = new Contained ();
}
~Container ()
{
m_oContained = null;
}
}
Now create an instance of Container then immediately set to null so
that the newly created object is due for garbage collection e.g.:
Container l_oTest = new Container();
l_oTest = null;
What I don't understand is this: the Contained destructor is being
called BEFORE the Container destructor. This doesn't make sense to me
as a reference to the Contained object ( namely m_oContained ) still
exists when the Contained destructor is called. Indeed, when the
Container destructor is later called, the watch window reports
m_oContained as still referencing a valid object?!
Thanks in advance
in the following example:
class Contained
{
~Contained ()
{
}
}
class Container
{
Contained m_oContained;
public Container ()
{
m_oContained = new Contained ();
}
~Container ()
{
m_oContained = null;
}
}
Now create an instance of Container then immediately set to null so
that the newly created object is due for garbage collection e.g.:
Container l_oTest = new Container();
l_oTest = null;
What I don't understand is this: the Contained destructor is being
called BEFORE the Container destructor. This doesn't make sense to me
as a reference to the Contained object ( namely m_oContained ) still
exists when the Contained destructor is called. Indeed, when the
Container destructor is later called, the watch window reports
m_oContained as still referencing a valid object?!
Thanks in advance