none
why do we need to prevent Circular Object References RRS feed

  • Question

  • I'm new to this. Can you please explain to me why the "Circular REference" is a bad thing, what's the bad result it may bring about?
    Wednesday, May 6, 2015 3:02 PM

Answers

  • Some code that recusively enumerates parent/child relationships can get caught in an infinite loop.

    Richard Mueller - MVP Directory Services

    Wednesday, May 6, 2015 3:32 PM
  • Circular objects references a bad thing in .NET? Nope.

    You probably heard this in a context where reference counting is used to manage memory instead of garbage collection. When reference counting is used circular object references can cause memory leaks.

    Wednesday, May 6, 2015 3:34 PM
    Moderator
  • It depends on the context. For example a circular reference leads to a deadlock when two or more threads are each waiting for another to release a lock. And a circular reference in your code, for example where method A calls method B which in turn calls method A, may lead to a Stackoverflow exception. You can read about more scenarios here: http://en.wikipedia.org/wiki/Circular_reference.

    But circular references are not always harmful: http://stackoverflow.com/questions/1897537/why-are-circular-references-considered-harmful

    Hope that helps.

    Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't ask several questions in the same thread.

    Wednesday, May 6, 2015 3:49 PM

All replies

  • Some code that recusively enumerates parent/child relationships can get caught in an infinite loop.

    Richard Mueller - MVP Directory Services

    Wednesday, May 6, 2015 3:32 PM
  • Circular objects references a bad thing in .NET? Nope.

    You probably heard this in a context where reference counting is used to manage memory instead of garbage collection. When reference counting is used circular object references can cause memory leaks.

    Wednesday, May 6, 2015 3:34 PM
    Moderator
  • It depends on the context. For example a circular reference leads to a deadlock when two or more threads are each waiting for another to release a lock. And a circular reference in your code, for example where method A calls method B which in turn calls method A, may lead to a Stackoverflow exception. You can read about more scenarios here: http://en.wikipedia.org/wiki/Circular_reference.

    But circular references are not always harmful: http://stackoverflow.com/questions/1897537/why-are-circular-references-considered-harmful

    Hope that helps.

    Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't ask several questions in the same thread.

    Wednesday, May 6, 2015 3:49 PM
  • thank you for your reply.
    Wednesday, May 6, 2015 6:17 PM
  • I like what's up, what's working, can you please clear it?
    Wednesday, May 6, 2015 7:21 PM