Questions tagged [cyclic-reference]

A cyclic reference is established if object A holds a reference to B while B holds a reference to A.

A cyclic reference is established if object A holds a reference to B while B holds a reference to A. This exposes a dynamic problem ("hen-vs-egg"), for instance in a programming language, to create a cyclic reference, A and B must be known prior to establishing their inter-relationship. Thus a form of temporal sequence (delay) is needed if data structures are purely functional, for example by declaring the initialization of the references lazy. Cyclic references can also pose problems to garbage collection which needs to detect that none of two objects involved in a cyclic reference are reachable any more by the rest of the code.

143 questions
8
votes
1 answer

Refactoring domain model with mutability and cyclical dependencies to work for Scala with good FP practices?

I come from an OO background(C#, javascript) and Scala is my first foray into FP. Because of my background I am having trouble realizing a domain model that fits my domain problem well and also complies with good practices for FP such as minimal…
8
votes
4 answers

Why is there no cyclic layout issue for classes in C#?

public struct Unit { Unit u; } Causes: Struct member 'Unit.u' of type 'Unit' causes a cycle in the struct layout. But public class Unit { Unit u; } compiles. I understand the problem I suppose. An endless cycle will be formed when…
nawfal
  • 70,104
  • 56
  • 326
  • 368
7
votes
1 answer

Explanation for "illegal cyclic reference" involving implicits

In my project, I have a type A, used for arguments in a few places, where I want a bunch of types automatically converted to that type. I've implemented this using a few implicit classes in the companion object of A. I've removed everything not…
Feuermurmel
  • 9,490
  • 10
  • 60
  • 90
7
votes
3 answers

Avoiding indirect cyclic references when using shared_ptr and weak_ptr

I'm currently putting together an application that relies heavily on shared_ptr and everything looks good so far - I've done my homework and have a pretty good idea of some of the pitfalls of using shared_ptrs. One of the most recognised problems…
Alan
  • 13,510
  • 9
  • 44
  • 50
6
votes
1 answer

SQL SELECT to find cyclic references in father-ID-organized tree?

"Fun" with cyclic references: Suppose I have a table ELEMENTS which contain a hierarchy of elements, modeled by a father ID. The father ID field is null for the root. All other records have a non-null father id with the (autosequenced) primary key…
TheBlastOne
  • 4,291
  • 3
  • 38
  • 72
6
votes
0 answers

CyclicalReferenceException while using Betwixt

I have cyclical references in my hibernate domain model which is causing Betwixt to fail. I don't want to change my domain model. How do I change Betwixt to ignore the cyclical reference?
user39554
  • 61
  • 1
6
votes
1 answer

Referencing a containing struct in Rust (and calling methods on it)

Editor's note: This code example is from a version of Rust prior to 1.0 and is not syntactically valid Rust 1.0 code. Updated versions of this code produce different errors, but the answers still contain valuable information. I'm trying to write a…
Kolja
  • 1,197
  • 9
  • 17
6
votes
2 answers

Is every cyclic references between Java packages bad?

I've been using Sonar code quality management platform for some time, and for the most cases I find it very helpful in revealing hidden design flaws of my code base. However, there's one rule that gives me more annoyance than help and that is its…
mysticfall
  • 302
  • 2
  • 7
5
votes
1 answer

AttributeError when using python deepcopy

I have a class that has __eq__ and __hash__ overridden, to make its objects act as dictionary keys. Each object also carries a dictionary, keyed by other objects of the same class. I get a weird AttributeError when I try to deepcopy the whole…
Evgeny Tanhilevich
  • 1,119
  • 1
  • 8
  • 17
5
votes
1 answer

Breaking cyclic references with std::weak_ptr and alias constructor: sound or problematic?

I have not yet found the following way of breaking cyclic references explained on any major C++ forum/blog, like on GotW, so I wanted to ask whether the technique is known, and what are its pro and cons? class Node : public…
Johannes Schaub - litb
  • 496,577
  • 130
  • 894
  • 1,212
5
votes
2 answers

Detect whether cyclic reference in object A is structurally the same as cyclic reference in object B

I am implementing a function that compares two JavaScript objects for "deep" equality. The skeleton of this function, right now, looks like this: function check_equal(actual, expected) { var stack = []; function check_equal_r(act, exp) { …
zwol
  • 135,547
  • 38
  • 252
  • 361
5
votes
2 answers

Building a project with mixed Scala and Java source files using Ant - illegal cyclic reference error

At the present time I have an existing Java project with Ant build that I am trying to set up to build with mixed source (Java and Scala). I hava a Java interface defined as - public interface One> that when I run scalac…
5
votes
1 answer

In Python, what is the reference count of cyclic reference and why?

Here is a example of a cyclic reference of Python. >>> a = [1] >>> b = [2] >>> a.append(b) >>> b.append(a) after this, >>> sys.getrefcount(a) = 3 >>> sys.getrefcount(b) = 3 Why do a and b have a reference count of 3?? Sorry guys i just took a…
nextdoordoc
  • 1,727
  • 6
  • 20
  • 30
4
votes
2 answers

cyclic dependency - structures and function pointer referencing each other

I am not able to compile the following program because of cyclic dependency between a structure and a function pointer. // fnPtr.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "stdlib.h" //typedef…
Saurabh Ghorpade
  • 1,137
  • 5
  • 15
  • 22
4
votes
2 answers

C++ cyclic inclusion issue

I have this file logger.hpp: #ifndef _LOGGER_HPP_ #define _LOGGER_HPP_ #include "event.hpp" // Class definitions class Logger { public: /*! * Constructor */ Logger(); /*! * Destructor */ ~Logger(); /*! …
Andry
  • 16,172
  • 27
  • 138
  • 246
1
2
3
9 10