According to Dawkins, it is a mistake to assume that an ecosystem or a species as a whole exists for a purpose.
As long as an organism survives its childhood and manages to reproduce thus passing its genes down to the next generation, what happens to the parent organism afterwards does not really bother genes.