How to recycle obstacles in an Endless Runner?

Hi I am creating an Endless Runner for Android, the problem is that obstacles slow down my game, so I don’t know how to get them to recycle since they are created infinitely, and another problem is that they are not destroyed by leaving them behind.

This is my code to randomly generate:

 using System.Collections;
 using UnityEngine;
 
 public class GenerateCube : MonoBehaviour
 {
     public GameObject CubeObj;
     Vector3 Pos;
     bool next;
     public float[] posX;
     public float[] posZ;
     int value = 1;
     public int lastpos = 1;
 
     void FixedUpdate(){
         next = true;
         Generate ();
     }
     void Generate(){
         if (!next)
             return;
         int i = Random.Range (0, 3);
         Pos.x = posX*;*

Pos.z += posZ*;*
GameObject CubeClone = Instantiate(CubeObj, Pos, CubeObj.transform.rotation);
CubeClone.GetComponent().myNum = value;
CubeClone.transform.SetParent (this.transform);
value += 1;
next = false;
return;
}
public void Message(int i){
if(lastpos == i) {
lastpos += 1;

}
}
}

see Introduction to Object Pooling - Unity Learn for how to do it.