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
25
votes
3 answers

Is circular reference between objects a bad practice?

I have a Model that will "carry" (Model.validator) a validator instance with it, and I need the Validator to have access to the Model's attributes. So, what I have come up with is the following var Validator = function(model) { this.model =…
Knorcedger
  • 253
  • 3
  • 4
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
  • 93,734
  • 56
  • 203
  • 318
23
votes
2 answers

Implementing Bi-Directional relationships in MongoEngine

I'm building a Django application that uses MongoDB and MongoEngine to store data. To present a simplified version of my problem, say I want to have two classes: User and Page. Each page should associate itself with a user and each user a page. from…
23
votes
2 answers

How To Fix Circular Reference Error When Dealing With Json

This question is a part of my original post here Get Data Into Extjs GridPanel Below is my Controller that reads data from sql db and then I am trying to encode the result as JSON and send the data back to my gridview.js public JsonResult…
EagleFox
  • 1,367
  • 10
  • 34
  • 58
22
votes
5 answers

Javascript Deep Clone Object with Circular References

I have copied the function below from an existing answer by Dmitriy Pichugin. This function can deep clone an object without any circular references- it works. function deepClone( obj ) { if( !obj || true == obj ) //this also handles boolean as…
Lucien
  • 776
  • 3
  • 12
  • 40
22
votes
2 answers

Is it possible to create circular references in Clojure?

Ignoring native interop and transients, is it possible to create any data structures in Clojure that contain direct circular references ? It would seem that immutable data structures can only ever contain references to previous versions of…
Nick Main
  • 1,440
  • 8
  • 15
22
votes
2 answers

Creating circular generic references

I am writing an application to do some distributed calculations in a peer to peer network. In defining the network I have two class the P2PNetwork and P2PClient. I want these to be generic and so have the definitions of: P2PNetwork
M. Jessup
  • 8,153
  • 1
  • 29
  • 29
21
votes
3 answers

In Nodejs, when I console.log a req object, what does [Circular] reference? How to determine that

In Nodejs, when I console.log a req object, what does [Circular] mean? Here's an example console.log(req) against a basic nodejs example. Notice the request.socket._readWatcher.socket is a [Circular]. Does that mean it refers to itself? How can I…
jcolebrand
  • 15,889
  • 12
  • 75
  • 121
20
votes
6 answers

Circular reference causing stack overflow with Automapper

I'm using Automapper to map my NHibernate proxy objects (DTO) to my CSLA business objects I'm using Fluent NHibernate to create the mappings - this is working fine The problem I have is that the Order has a collection of OrderLines and each of these…
Charleh
  • 13,749
  • 3
  • 37
  • 57
20
votes
4 answers

I have a circular reference. How can I create a weak reference in Objective-C?

I'm working on an iPhone application. I have an object of class Row that needs to release numerous objects of the class Block. Every Block currently has a property that retains an instance variable of class Row. @interface Block : UIImageView { …
Tozar
  • 976
  • 9
  • 20
19
votes
5 answers

Is there a way to detect circular arrays in pure PHP?

I'm trying to implement my own serialization / var_dump style function in PHP. It seems impossible if there is the possibility of circular arrays (which there is). In recent PHP versions, var_dump seems to detect circular arrays: php > $a =…
postfuturist
  • 22,211
  • 11
  • 65
  • 85
16
votes
8 answers

getting around circular references in Delphi

Is there a way of getting around circular unit references in Delphi? Maybe a newer version of delphi or some magic hack or something? My delphi project has 100 000+ lines of code mostly based on singleton classes. I need to refactor this, but that…
Tom
  • 1,047
  • 4
  • 15
  • 27
16
votes
9 answers

How to avoid circular unit reference?

Imagine the following two classes of a chess game: TChessBoard = class private FBoard : array [1..8, 1..8] of TChessPiece; ... end; TChessPiece = class abstract public procedure GetMoveTargets (BoardPos : TPoint; Board : TChessBoard;…
jpfollenius
  • 16,456
  • 10
  • 90
  • 156
16
votes
2 answers

Initializing circular data in C. Is this valid C code according to any standard?

I wanted to see if I could initialize a global variable to point to itself: #include struct foo { struct foo *a, *b; } x = { &x, &x }; int main() { printf("&x = %p, x.a = %p, x.b = %p\n", &x, x.a, x.b); return 0; } This code…
Matt
  • 21,026
  • 18
  • 63
  • 115
16
votes
13 answers

What solutions are there for circular references?

When using reference counting, what are possible solutions/techniques to deal with circular references? The most well-known solution is using weak references, however many articles about the subject imply that there are other methods as well, but…
OB OB
  • 3,289
  • 6
  • 21
  • 16
1
2
3
50 51