ASP.Net C# garbage collection deals with circular references - What are circular references?

A circular reference is a run-around wherein the two or more resources are interdependent on each other rendering the entire chain of references to be unusable.

There are quite a few ways of handling the problem of detecting and collecting cyclic references.
  • A system may explicitly forbid reference cycles.
  • Systems at times ignore cycles when they have short lives and a small amount of cyclic garbage. In this case a methodology of avoiding cyclic data structures is applied at the expense of efficiency.
  • Another solution is to periodically use a tracing garbage collector cycles.
Other types of methods to deal with cyclic references are:
  • Weighted reference counting
  • Indirect reference counting
Circular References with Dependency Injection

Dependency injection mechanisms carry the risk of unintentional circular references, which are not easy to detect or prevent. This topic describes the situations where you may inadvertently cause circular references to occur, resulting in a stack overflow and application error. The most common causes of circular references with dependency injection are the following:
  • Objects generated through constructor injection that reference each other in their constructor parameters
  • Objects generated through constructor injection where an instance of a class is passed as a parameter to its own constructor
  • Objects generated through method call injection that reference each other
  • Objects generated through property injection that reference each other
Tags:
Hot on Web:


About author