World Removal Memory Leak


(Darrin) #1

Happy holidays all! Almost ready to post my new game. That last 10 percent is 50 percent of the work. Two quick questions.

  1. [SOLVED] How do I make a rounded progress bar something like this from Zach? I have a square render working perfectly but this one just looks damn nice! Use Draw.rectPlus radius feature.

  2. What is the best practice to remove a world? For some reason I still get more memory every time I switch worlds. So I ran the game. 80 mb on start. I then went to my about screen 5 times. 104 mb after the five runs. I let it sit for 10 minutes (I timed it). No change in memory. This is actually quite concerning as I hope to build a bigger game with multiple levels that the player will go back and forth on. No one else sees this?

Note there is no change in memory since I did not create a new title world when I go back to the title world but when I go from title world to about world it increases by 5 MB every time.

if (btnBack.click()) {
			FP.world.removeAll();
			FP.world = null;  // this cleans up a little of the memory
			FP.world = title;
		}

(Ben Pettengill) #2
  1. To draw a rounded rectangle, check out Flashpunk’s draw class. the command Draw.rectPlus actually has a radius parameter that lets you set how rounded the corners are on the rectangle you draw.

  2. As far as I know, Flashpunk automatically removes all entities when you switch worlds. Switching worlds will always increase memory a little, because Flash doesn’t garbage collect the memory from the previous world right away. If things are working properly, the memory use should drop down after a few seconds (or minutes… or after changing worlds a few times).


(Darrin) #3
  1. [SOLVED] Rounded corner. Ben, Okay the draw is solved perfectly. Thanks!

  2. So I ran the game. 80 mb on start. I then went to my about screen 5 times. 104 mb after the five runs. I let it sit for 10 minutes (I timed it). No change in memory. This is actually quite concerning as I hope to build a bigger game with multiple levels that the player will go back and forth on. No one else sees this?