unity – Exclude removed objects from list counting?


I want to count the number of objects on my list. But because I remove and add, my script keep count those empty elements.

update: This happen when I destroy the object when it inside the collider. This object does not get out from “OnTriggerExit2D”.

public List<GameObject> Sorts;
public List<GameObject> ItemsInside;
public int NumSorts, NumItems;


// Update is called once per frame
void Update()
{
    NumSorts = Sorts.Count;
    NumItems = ItemsInside.Count; // it doesn't give correct number 

}

void OnTriggerEnter2D(Collider2D other)
{
    if (other.CompareTag("Sort"))
    {
        Sorts.Add(other.transform.gameObject);

    }
    if (other.transform.name == ("GameItem"))
    {
        ItemsInside.Add(other.transform.gameObject);

    }
}

void OnTriggerExit2D(Collider2D otherOut)
{

    if (otherOut.CompareTag("Sort"))
    {
        Sorts.Remove(otherOut.transform.gameObject);
    }
    if (otherOut.transform.name == ("GameItem"))
    {
        ItemsInside.Remove(otherOut.transform.gameObject);
    }


}