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

Can using Scalar::Util's weaken cause invalid reference problems?

Please see this related question for some background information. When I say "invalid reference" I mean a reference that points to no data. Assume we have the following data structure containing cyclic references: …
tjwrona1992
  • 8,614
  • 8
  • 35
  • 98
4
votes
1 answer

Circular dependency with constructor injection

Say I have the following components: Producer produces numbers and sends messages to Consumer Both Producer and Consumer send messages to Monitor Monitor, say randomly, decides when the produce / consume process should stop and sends a message to…
levant pied
  • 3,886
  • 5
  • 37
  • 56
4
votes
2 answers

Role of weak_ptr in shared_ptr

I understand how a shared_ptr works except for the role of the weak_ptr. I understand its there to detect circular references when the reference count isn't zero, but beyond this I don't understand just exactly how it does this. What does it do?
user997112
  • 29,025
  • 43
  • 182
  • 361
4
votes
3 answers

Resolving cyclic references in jaxb

I'm dealing with some cyclic references while implementing my project's web service layer. I'm using jaxb (latest version, 2.2.7) and even I had a look to some tips as here and here I can't get it working. That's a basic SSCCE about my problem: /* *…
Aritz
  • 30,971
  • 16
  • 136
  • 217
4
votes
3 answers

C++ ERROR: forward declaration of 'struct...?

cyclical inclusion problem I forward declare one of the classes in the header of the other in an attempt to solve their cyclical inclusion. Here are my two files: The first file (Parameter.h): #pragma once #include "Token.h"` class…
amorimluc
  • 1,661
  • 5
  • 22
  • 32
3
votes
4 answers

A Class modelling /design query

How would I model such a situation? How should the database be designed? What classes should I have? Problem Statement: Each employee belongs at least to one project, each project has many tasks, each task is assigned to at least one employee. I…
user115263
3
votes
4 answers

How can I detect or avoid cyclic references with std::shared_ptr?

I know that there is weak_ptr to break the cycle, but that is a fix, after the problem is discovered. Is there a pattern or tool that can be used to either detect or avoid cyclic referencing?
Tamás Szelei
  • 23,169
  • 18
  • 105
  • 180
3
votes
0 answers

Axios and TypeError: "cyclic object value"

I keep getting the error in the title and cant figure out why. I have painful quest to generate multiple (5-10) pdf files at once, and send all of them to my server. when i click button, it will trigger this for loop which generates rows and colums…
Clomez
  • 1,410
  • 3
  • 21
  • 41
3
votes
1 answer

endless loop on code analysis with FxCop Introspection

I'm trying to write a custom FxCop code analysis rule that will warn developers from methods containing too deeply nested code blocks, and will urge them to re-factor out the mess. ex. I'm trying to avoid the following situation: if(condition) { …
Paul
  • 1,757
  • 2
  • 11
  • 21
3
votes
1 answer

Is it bad practice, or likely to suffer performance issues, to store circular dependencies in objects?

Is it bad practice or have a significant performance impact to have a cyclical reference? e.g., add object A as property of object B and then Object B as property of Object A? An example:
3
votes
1 answer

Fabrication gem cyclic dependency

I've got a cyclic dependency when worked with fabrication gem. Here I'll show you what I've did. Let's suppose I have 2 models: class User < AR::Base has_many :messages class Message < AR::Base belongs_to :user So, the fabricators for them…
3
votes
1 answer

Is there a way to serialize cyclic data structures with encoding/gob?

I'm working on porting a neural network library to Go. I want to be able to save and restore a trained network, so I'm attempting to serialize it directly. The problem is, the network struct contains cycles in its field (Neuron A has a connection to…
Joel
  • 1,437
  • 2
  • 18
  • 28
3
votes
2 answers

java cyclic reference and garbage collections

Let's consider the following 2 cyclic referencing examples: Straight forward cyclic referencing class A { B b; } class B { A a; } WeakReferenceing class A { B b; } class B { WeakReference aRef; } The following…
Yaneeve
  • 4,751
  • 10
  • 49
  • 87
3
votes
3 answers

How to do cleanup reliably in python?

I have some ctypes bindings, and for each body.New I should call body.Free. The library I'm binding doesn't have allocation routines insulated out from the rest of the code (they can be called about anywhere there), and to use couple of useful…
Cheery
  • 24,645
  • 16
  • 59
  • 83
3
votes
1 answer

Cyclic Template

Suppose template class A is defined as follows: template class A { B b; }; Suppose template class B is defined as follows: template class B { A a; }; Ideally, these classes would be defined in separate…
Sam Hertz
  • 161
  • 9
1 2
3
9 10