How garbage collector collects internal objects inside other objects? : <p>Let's say we have two class A and class B:</p>

<pre><code>class A
{
   public B b;
   public A()
   {
       b = new B();
   }
}

class B
{

}
</code></pre>

<p>and in the main method:</p>

<pre><code>static void Main(string[] args)
{
  TestMethod();
  //timestamp 2
  string[] StrList = new String[999999]; // Make a ton of objects to trigger Garage Collection in an attempt to free up memory
}

static void TestMethod() 
{
   A a = new A();
   //timestamp 1
}
</code></pre>

<p>so in timestamp 1, the memory will be like:</p>

<p><a href="https://i.stack.imgur.com/egjGV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/egjGV.png" alt="enter image description here"></a></p>

<p>and in timestamp 2, the memory will be like:
<a href="https://i.stack.imgur.com/lI0Ut.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lI0Ut.png" alt="enter image description here"></a></p>

<p>and then GC is triggered. The first thing I don't quite understand is, how the instance new B() free by GC? since b is still pointing to it, and GC won't collect objects that are still be referenced?</p>

<p>If new B() has to be free , which one is free first, new A() or new B()?</p>
