1

I wanted to check .NET Profiler and how it indicates about circular reference but i think i don't understand something because i see that i have 0 Live instances once the controller action finish the operation...

This is the controller action:

[AllowAnonymous]
public ActionResult Index()
{
  var b = new B();
  var c = new C();
  b.x = c;
  c.x = b;

  return PartialView();
}

}

This is the result of the .NET Profiller:

enter image description here

I don't understand if the GC success to collect the objects when the action is finished or i am not looking at the right place in the .NET Profiller diagrams.

The same thing is with DotMem application.

Omtechguy
  • 3,321
  • 7
  • 37
  • 71
  • 2
    There is a circular reference between `b` and `c` but they both become unreachable when `Index` ends so GC may collect them. – Konrad Kokosa Jan 24 '18 at 10:16
  • @KonradKokosa So if i have circular reference inside an object, and i dispose the parent object, the GC will collect also the circular reference without any side affects? – Omtechguy Jan 24 '18 at 10:25
  • 1
    yes because CLR uses marking to identify reachable objects. It starts from roots (like local variables) and traverses whole object's graph. But it won't "visit" already "visited" object so circular references are not a problem. – Konrad Kokosa Jan 24 '18 at 10:31
  • Possible duplicate of [Garbage collector and circular reference](https://stackoverflow.com/questions/8840567/garbage-collector-and-circular-reference) – Konrad Kokosa Jan 24 '18 at 13:46

0 Answers0