How to avoid running out of solutions in genetic algorithm due to selection?
There are multiple ways to interpret those steps. The most common standard approaches are

select two parents and produce two offspring; repeat until child population is the same size as parent population, and let the children replace their parents unconditionally (generational GA)

same as the above, but allow a few parents to live on instead of a few children if the parents have higher fitness (elitism)

each iteration, select two parents, produce one child, let the child replace a member of the parent population if it is better (steady state GA)


But there are other ways to go. There's an algorithm called CHC that lets the child population get smaller over time, and when it reaches zero, the algorithm triggers a smart restart. The point is there's no single definition for what makes an evolutionary algorithm. It's up to you to decide how to make something that works well for your problem. When you're a beginner though, it's handy to start from known points, like the three I mentioned above.