Question by
SanQri · May 11, 2019 at 01:20 PM ·
memorymemory managementmemory-leakmemory usagememory leak
What is the correct way to store circular references in Unity?
Let's suppose we have code like this:
public class ComponentA : MonoBehaviour {
B b;
void Start() {
b = new B();
b.a = this;
}
}
public class B {
public ComponentA a;
}
So will memory be freed (ComponentA destroyed) after destroying game object with attached ComponentA?
I'm not sure, but answer is yes. So for which reason there is WeakReference<> in System namespace?
Comment
Answer by Owen-Reynolds · May 11, 2019 at 03:02 PM
C# uses a reachability test to find garbage, copied from Java, so circular references are fine. The language has weak references since dot-NET has them anyway, so why not?
Your answer
Follow this Question
Related Questions
Run out of memory in build 1 Answer
Memory error pls help 0 Answers
WebGl project memory usage 1 Answer
Unity Total System Memory Usage GO CRAZY?! memory leak 0 Answers