Clear Does not work to remove

I am creating buttons where the buttons will generate prefabs. Then I am creating a list to store each instantiated prefab object, I am now trying to create a button to clear all the instantiated objects from the scene… however it does not seem to be working…

public class objectiveGenerate : MonoBehaviour {

    public Button buttonSelect;
    public GameObject myPrefab;

    public List<GameObject> generatedObjects = new List<GameObject>();


    void Start()
    {
        buttonSelect.onClick.AddListener(objectiveTask);
    }


    public void objectiveTask() 
    {
        if (EventSystem.current.currentSelectedGameObject.name == "buttonCube")
        {
            GameObject Cube = Instantiate(myPrefab);
            Cube.transform.position = new Vector3(0, 0.5f, 0);
            generatedObjects.Add(Cube);

        }

        else if (EventSystem.current.currentSelectedGameObject.name == "buttonClear")
        {
            foreach(var obj in generatedObjects)
            {
                Destroy(obj);
             }
             generatedObjects.Clear();
         }
     }

}

You are clearing the list and then going through it destroying its contents.

You probably want to be doing that the other way around.