Whenever you have a script that instantiates GameObjects, you must be aware of the life cycle of the object and possibly arrange to destroy it when it is no longer needed. In object-oriented programming (OOP), the life cycle of an object begins when a block of memory is allocated that is large enough to hold the object. When the object is destroyed, its memory is released and reclaimed by the system. In this section, we will examine different strategies on how to decide when to destroy GameObjects you have created, including destroying after they're no longer visible in the scene, or after a specific life duration. Then, we'll use a technique called object pooling to avoid problems caused by repeatedly instantiating and destroying objects at runtime.
Removing fallen objects
In our scene, we have a limited-size ground plane and as balls hit one another, some will fall off the plane into oblivion. At that point, we can...