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
15
votes
2 answers

Is It possible to perform serialization with circular references?

So, my entity class (written in C#) follows a parent child model where every child object must have a Parent property in which it keeps reference of its Parent. This Parent property causes issues in serialization of the Object due to circular…
Arpit Khandelwal
  • 1,743
  • 3
  • 23
  • 34
15
votes
1 answer

Chrome/V8 does not garbage collect a circular reference?

Take a look at this part of a Chrome heap snapshot: It shows the retainers of an object in the heap that, as far as I know and can see, should be garbage, but is not collected despite that. The "shortest" path to the root is, after all, a cyclical…
15
votes
4 answers

Garbage collection in Perl

Unlike Java, Perl uses reference count for garbage collection. I have tried searching some previous questions which speak about C++ RAII and smart pointers and Java GC but have not understood how Perl deals with the circular referencing problem.…
srikanta
  • 2,914
  • 3
  • 21
  • 35
15
votes
4 answers

How to prevent a self-referencing table from becoming circular

This is a pretty common problem but I haven't yet found the exact question and answer I'm looking for. I have one table that has a FK pointing to its own PK, to enable an arbitrarily deep hierarchy, like the classic tblEmployee that has a column…
East of Nowhere
  • 1,354
  • 4
  • 18
  • 27
14
votes
4 answers

Any nice tools for untying knots in Haskell?

I've a data structure with several different types of internal circular linking, making it infinite in the sense of say the cycle command. Are there any interesting modules for collapsing such structures into flat data structures that use indexing…
Jeff Burdges
  • 4,204
  • 23
  • 46
14
votes
2 answers

Circular reference in Kotlin Enum

How can I create an enum class with circular references? Simple example (taken from this Java question): enum class Hand(val beats: Hand) { ROCK(SCISSORS), // Enum entry 'SCISSORS' is uninitialized here PAPER(ROCK), SCISSORS(PAPER); }
Michael Hoff
  • 6,119
  • 1
  • 14
  • 38
14
votes
3 answers

How to use @JsonIdentityInfo with circular references?

I am trying to use the @JsonIdentityInfo from Jackson 2 as described here. For testing purposes I created the following two classes: public class A { private B b; // constructor(s) and getter/setter omitted } public class B { private A…
Burkhard
  • 14,596
  • 22
  • 87
  • 108
14
votes
3 answers

How do I detect circular logic or recursion in a multi-levels references and dependencies

I have a graph of multi-level dependecies like this, and I need to detect any circular reference in this graph. A = B B = C C = [D, B] D = [C, A] Somebody have a problem like this? Any solution??? Thanks and sorry by english. ========= updated…
LuigleDR
  • 309
  • 1
  • 2
  • 13
13
votes
4 answers

Circular reference in same assembly a bad thing?

Assume I have the following classes in the same assembly public class ParentClass : IDisposable { public ChildClass Child { get { return _child; } } } public class ChildClass { public ParentClass Parent { get { return…
user20358
  • 14,182
  • 36
  • 114
  • 186
13
votes
3 answers

Does Dart/Flutter have the concept of weak references?

I'm in the early stages of learning Dart & Flutter. I'm looking at how to implement an eventbus, which works fine, but I've noticed that Widgets (and/or their associated state) hold a strong reference to the (global) eventbus, causing a memory leak.…
hunter
  • 872
  • 10
  • 26
13
votes
2 answers

JavaScriptSerializer circular reference when using ScriptIgnore

I have my Entity Framework Entities split out into a separate class library from my web project and data access layer. In my controller I make a call to my repository to get an IEnumerable and then try to serialize into json…
12
votes
2 answers

in_array on objects with circular references

I'm building an array of objects. I need this array to only contain once instance of a given object, having multiple references to the same object should throw an exception. I'm using the following code to achieve this: public function addField…
GordonM
  • 31,179
  • 15
  • 87
  • 129
12
votes
4 answers

Is there a solution about Gson "circular reference"?

I have found many articles about the circular reference with Gson, but I can't find an elegant solution. As I know, some solutions is: Set the property that caused circular reference as "transient". exclude the property with some annotation. But…
Johnny Fee
  • 121
  • 1
  • 3
12
votes
6 answers

Is there a way to test circular reference in JavaScript?

I'm making a game, and I've come across a problem... When I try to save, JSON fails and reports that circular reference is being made somewhere. I don't think it actually is, I can't see it, so is there an algorithm or anything which could tell me…
corazza
  • 31,222
  • 37
  • 115
  • 186
12
votes
1 answer

Avoid Circular Model Imports in Django Apps

I have a django project with 2 apps like this: ## tags app, models.py class Tag(models.Model): title = models.CharField(max_length=50) ## items app, models.py from application.tags.models import Tag class Item(models.Model): title =…
jkeesh
  • 3,289
  • 3
  • 29
  • 42
1 2
3
50 51