Circular references!

Source: Internet
Author: User

What is circular reference?

For example, it is easier to describe this problem:

Class Program
{
Static void main (string [] ARGs)
{
B = new B ();
}
}
Public Class
{
Public B = new B ();
}

Public Class B
{
Public A = new ();

}

Field a References field B and field B References field A, which leads to the issue of circular reference. Unfortunately, the C # compiler cannot detect such problems!

IfCodeIf this is the case, a new object will be allocated continuously in the heap, and an stackoverflowexception exception will be thrown.

Of course, this is not what everyone writes, because it is obvious that circular references exist here.

but sometimes this problem is relatively obscure. It may be that a references B, B references C, C references D, and D References, this problem eventually occurs. Write This article to attract your attention.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.