Unity "The object of type 'Object' has been destroyed but you are still trying to access it."

Hi all
I am making a toggle script so when you click on the toggle you can hide/show objects.
However I am getting this error:
MissingReferenceException: The object of type ‘Object’ has been destroyed but you are still trying to access it.

Here is the code:

public GameObject[] objects;

    // Use this for initialization
    void Start () {

    }

    // Update is called once per frame
    void Update () {

    }
    void OnGUI(){
        foreach (GameObject go in objects) {
            bool active=GUILayout.Toggle (go.activeSelf, go.name);
            if (active != go.activeSelf)
                go.SetActive (active);
        }
    }
}

I need help in identifying and solving the problem.
Thanks

One of GameObject in objects array got Destroy(…) call on it (or was unloaded with scene possibly) and thus was destroyed. And you don’t remove it from objects array so in foreach loop you try to access reference to destroyed object.

During your foreach loop, one of the object you are calling via go is not valid anymore.
Run your script in debug mode to know which one.