I’m working on an app with lots of bouncing balls. Let’s say there are 100 of them. They’ll move around using the physics APIs, not transition.to(). Some balls will bounce off the screen, and new balls will be added.
I don’t want to leak memory. Two approaches come to mind:
1.) When a ball is created, store it in a table. In a game loop, traverse the table and test if the ball has moved off screen by looking at its x,y position. If it has left the screen, call removeSelf() and then call table.remove() to remove that ball from the table.
2.) Put invisible sensor objects at the display’s borders. When a collision occurs between a ball and the sensor, remove the ball. No game loop necessary.
Thoughts?