Does C# List.Add() clone GameObject?

When I add a GameObject to a generic list, but later destroy the object, it disappears from the world yet the list still contains an identical GameObject. Is the List still hanging on to a reference to the original GameObject? If so, how come the object disappears from view? Likewise, if adding a GameObject to a List clones it, how come when I destroy the original object, the object in the list isn’t being rendered. A little unsure what is going on here, say if I wanted to count the number of enemies left to be destroyed.

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class SampleGameObjectList : MonoBehaviour {
	
	List<GameObject> gList = new List<GameObject>();
	
	void Start () 
	{
		GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
        cube.transform.position = new Vector3(5, 5, 5);
		gList.Add(cube);
		DestroyImmediate(cube);
	}
	
	void Update () 
	{
		Debug.Log(gList.Count);  // Always shows 1, even though nothing is rendered		
	}
}

When you add a gameObject to a list, just the reference variable that is pointing to the gameObject is added to the list. When you destroy the gameObject , the reference will become null but because the list is using it, garbage collector does not collect it however the value inside it is not relevant anymore.
The best way to get rid of it is to use something like this in the gameObject that you want to keep track of.
void Awake()
{
glist.Add(this.gameObject);
}

void OnDestroy()
{
glist.Remove(this.gameObject);
}

The list can be static or in a singleton manager class. Also you can use this by defining a method for removing from the list in your current script and call the method from that cube when it’s being destroyed.

The object is destroyed, but the reference to the instance will not be removed from the list. This is expected behaviour. If you actually looked in the list, you should find that it is null.

(I believe what actually happens is that because there is still a reference to it can’t be completely collected, but the actual GameObject is thrown away on unity-side, and the wrapper object inside the list will say it is null or something… You probably don’t need to be worrying about this though)

It’s putting the GameObject in a list. That is all. The reason it disappears when you delete it is because the list is not told to do anything with the GameObject. If you are putting a GameObject into a list at runtime, it will vanish from the list if you delete it. If you use a prefab, the item will not vanish from the list.

The list isn’t supposed to show anything, it is meant to store values in a list order, the same way as if you were to do this:

GameObject ob1;
GameObject ob2;
GameObject ob3;
GameObject ob4;

and so on, it doesn’t create the item. If you are looking for it to display, you could try this:

for(int i = 0; i < gList.Count; i++)
{
    Instantiate(gList*)) //Can't remember exact parameters, but you get the idea*

}