Question by
waqaswaqas · Dec 11, 2015 at 11:58 PM ·
listpooling
Will GameObject remove from List.RemoveAt() destroy automatically?
Will GameObject remove from List.RemoveAt() destroy automatically? or They just hide from hierarchy and exists in memory ? e.g :- In case of Object Pooling?
Comment
Best Answer
Answer by rutter · Dec 12, 2015 at 12:01 AM
Supposing your code is something like this:
void Start() {
GameObject go = new GameObject("demo");
List<GameObject> list = new List<GameObject>();
list.Add(go);
list.RemoveAt(0);
}
The demo
GameObject will still exist in the scene. The go
variable is a reference pointing to the GameObject, but it isn't the GameObject itself.
You can add that reference to a list, or remove it, without affecting the GameObject.
Hmmm great. What we have to do to destroy this gameObject ? Destroy(go)?
Your answer
![](https://koobas.hobune.stream/wayback/20220612052211im_/https://answers.unity.com/themes/thub/images/avi.jpg)