Saturday, April 9, 2011

1


Problem: A program was made in the Box2D physics engine where balls are created, bounce around for a bit, and then get deleted. As the program ran, it began to lag, despite the number of balls on the screen being constant. 

Impact: The program quickly became impossible to run from the massive amounts of lag it experienced. 

Solution: The balls were originally being deleted from the list they were held in, which was supposed to remove the only reference to them and let the operating system clear up its memory. However, since the balls were made in Box2D, the physics engine kept a reference to the ball’s body. Another call to ball.deleteBody() was needed before removing the ball from the list, to remove the last remaining reference to the balls and allow the operating system to clear up their memory.  

No comments:

Post a Comment