When objects are repeatedly instantiated and destroyed you will likely notice the occasional performance spike during garbage collection which can take several seconds before the frame rate smoothens again. This is very common when firing projectiles and creating explosions, but will also occur when painting and erasing tiles with associated game objects at runtime.
Instead of trashing unwanted objects it is better to recycle them so that they can be reused over and over again. This technique is usually referred to as pooling. Essentially unwanted objects are placed into a pool until they are needed once again; new instances only need to be created when the pool is empty. Continue reading


