Questions tagged [circular-reference]

A circular reference is a series of references where the last object references the first, resulting in a closed loop.

A circular reference is a series of references where the last object references the first, resulting in a closed loop.

Circular references can appear in computer programming when one piece of code requires the result from another, but that code needs the result from the first.

Information is taken from Wikipedia, more information available there.

758 questions
157
votes
26 answers

How to avoid the "Circular view path" exception with Spring MVC test

I have the following code in one of my controllers: @Controller @RequestMapping("/preference") public class PreferenceController { @RequestMapping(method = RequestMethod.GET, produces = "text/html") public String preference() { …
balteo
  • 23,602
  • 63
  • 219
  • 412
110
votes
9 answers

How did Microsoft create assemblies that have circular references?

In the .NET BCL there are circular references between: System.dll and System.Xml.dll System.dll and System.Configuration.dll System.Xml.dll and System.Configuration.dll Here's a screenshot from .NET Reflector that shows what I mean: How Microsoft…
Drew Noakes
  • 300,895
  • 165
  • 679
  • 742
72
votes
4 answers

Garbage collector and circular reference

Consider these two classes: public class A { B b; public A(B b) { this.b = b; } } public class B { A a; public B() { this.a = new A(this); } } If I have classes designed like above, would the objects of such classes be…
Nawaz
  • 353,942
  • 115
  • 666
  • 851
66
votes
6 answers

How to create a circularly referenced type in TypeScript?

I have the following code: type Document = number | string | Array; TypeScript complains with the following error: test.ts(7,6): error TS2456: Type alias 'Document' circularly references itself. Clearly circular references are not…
samvv
  • 1,934
  • 1
  • 18
  • 26
60
votes
3 answers

How and when to appropriately use weakref in Python

I have some code where instances of classes have parent<->child references to each other, e.g.: class Node: def __init__(self): self.parent = None self.children = {} def AddChild(self, name, child): child.parent =…
Richard Levasseur
  • 14,562
  • 6
  • 50
  • 63
53
votes
4 answers

How to serialize DOM node to JSON even if there are circular references?

I want to serialize DOM node or even whole window to JSON. For example: >> serialize(document) -> { "URL": "http://stackoverflow.com/posts/2303713", "body": { "aLink": "", "attributes": [ "getNamedItem":…
NVI
  • 14,907
  • 16
  • 65
  • 104
49
votes
9 answers

Using print_r and var_dump with circular reference

I'm using the MVC framework Symfony, and it seems a lot of the built-in objects I want to debug have circular references. This makes it impossible to print the variables with print_r() or var_dump() (since they follow circular references ad…
Christian Davén
  • 16,713
  • 12
  • 64
  • 77
48
votes
1 answer

Circular references in Javascript / Garbage collector

Can somebody explain in detail how Javascript engines deal with circular references ? Is there a big difference between browsers or even node.js ? What I'm talking about is an explicit back-/next reference within objects. For instance: var objA = { …
jAndy
  • 231,737
  • 57
  • 305
  • 359
39
votes
9 answers

Json and Circular Reference Exception

I have an object which has a circular reference to another object. Given the relationship between these objects this is the right design. To Illustrate Machine => Customer => Machine As is expected I run into an issue when I try to use Json to…
ahsteele
  • 26,243
  • 28
  • 134
  • 248
35
votes
2 answers

Converting circular structure to JSON -- Any way to find what field it is complaining about?

I'm trying to stringify(...) an object in Chrome, and I keep getting a "Converting circular structure to JSON" message, despite the fact that (as far as I know) no such structure exists. I've been over the code a dozen times and can't find any…
Mike
  • 2,434
  • 1
  • 16
  • 19
35
votes
1 answer

What lifetimes do I use to create Rust structs that reference each other cyclically?

I'd like to have struct members that know their parent. This is approximately what I'm trying to do: struct Parent<'me> { children: Vec>, } struct Child<'me> { parent: &'me Parent<'me>, i: i32, } fn main() { let mut p =…
Grumdrig
  • 16,588
  • 14
  • 58
  • 69
30
votes
4 answers

DOM: why is this a memory leak?

Consider this quote from the Mozilla Docs on JavaScript memory leaks: function addHandler() { var el = document.getElementById('el'); el.onclick = function() { this.style.backgroundColor = 'red'; } } The above code sets up the…
30
votes
3 answers

Spring circular reference example

I have a circular reference in one of my projects at work using spring, which I am unable to fix, and fails with the following error at startup: 'org.springframework.security.authenticationManager': Requested bean is currently in creation: Is there…
robbin
  • 1,924
  • 4
  • 20
  • 26
28
votes
4 answers

How to deal with circular references?

If I have those two projects: MyCompany.ERP.Billing MyCompany.ERP.Financial Billing asks/sends information to Financial and vice-versa. Both are too big so I don't want to put them in a single project. Visual Studio doesn't allow circular…
Eduardo
  • 5,645
  • 4
  • 49
  • 57
26
votes
3 answers

Json and Java - Circular Reference

I'm having and issue with the Circular reference. I have Rest Webservices which returns objects to the front end, the issue is when I try to return objects that have several references so as the result I get an infinite response, which generate…
Faabass
  • 1,394
  • 8
  • 29
  • 58
1
2 3
50 51