Memory Leak Switching Worlds


(Darrin) #1

I’m wondering if this is the Recycle/create issue of Flash.

So I have two worlds, Title and Play. Every time I go to Play I add 10 mb which is fine. However when I go back to Title, I still retain the 10 mb. so every Play adds 10 mb.

Adding FP.world = null; helped a ton but I can’t get the original title screen to be the same memory size of the first run. I don’t think Main.title is the issue as no memory there is no change when going backward to it. The Play just keeps increasing and doesn’t clean up. Entities go to zero. What else could I look for?

Below is the code for cleaning up Play.

		if ((gameOver && Input.check(Key.ANY) && bDone) || (gameOver && Input.mouseReleased && bDone))
		{
			if (score > Title.highScore)
				Title.highScore = totalScore;
			FP.world.removeAll();
			FP.world = null;  // this cleans up one memory leak...
			FP.world = Main.title;				
			gameOver = false;
			
		}