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.

677 questions
129
votes
21 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
  • 20,469
  • 52
  • 196
  • 362
109
votes
8 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
  • 266,361
  • 143
  • 616
  • 705
60
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
  • 327,095
  • 105
  • 629
  • 812
56
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
  • 12,953
  • 5
  • 47
  • 61
50
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
  • 13,771
  • 16
  • 60
  • 102
47
votes
5 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,514
  • 1
  • 16
  • 22
45
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
  • 212,463
  • 51
  • 293
  • 348
41
votes
8 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
  • 13,902
  • 10
  • 53
  • 68
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
  • 25,470
  • 26
  • 131
  • 238
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,316
  • 1
  • 14
  • 19
32
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
  • 14,990
  • 11
  • 53
  • 68
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…
28
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,754
  • 4
  • 16
  • 26
27
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
  • 4,583
  • 3
  • 40
  • 53
24
votes
3 answers

javascript, circular references and memory leaks

From what I recall of a not too distant past, Javascript interpreters suffered from memory leaking issues when faced with circular references. Is it still the case in the latest browsers? (e.g. Chrome, FF 3.5 etc)
jldupont
  • 82,560
  • 49
  • 190
  • 305
1
2 3
45 46