- Home /
relation between dereferencing and memory deletion
Hey guys! I have some programming question about unity and c#. I know that if heap alloc occurs in c# script, those memory need to be collected by garbage collector. But when it comes to unity Destroy(because it is c++?), I heard that it delete(free the memory) the game object. But, because of the script attached to game object, and the references linked complicatedly, it seems that script memory doesn't deleted by Destroy. And my guess is that, it must make the garbage collector slower. Actually, I saw the unity document https://unity3d.com/…/optimizing-garbage-collection-unity-g… but it didn't mentioned about the relation between dereferencing and memory deletion.
So, here's my question.
If I dereference objects in class, does it makes garbage collector works faster?
Does 1. apply equally to prefab links? ex)
public class Test : MonoBehaviour { // 1. case of reference to other alive object private Other _other; // 2. case of reference to prefab linked by editor [SerializeField] private Prefab _prefab; // ... // dereferences private void OnDestroy() { _other = null; _prefab = null; } }
If there isn't any reference to other objects, does this script can be deleted directly by Destroy? thank you !!
Your answer
Follow this Question
Related Questions
Prefab referenced into Inspector and then Istantiated: Twice in memory? 0 Answers
How to disable referenced Prefabs being preallocated in memory?? 0 Answers
Used heap is above 10MB, should I worry? 0 Answers
Unity iOS controlling heap size growth 1 Answer
Memory Leak: Base Class Script duplication on load 2 Answers