I have a question about degrading performance in XNA. I am using the GameStateManagement example from Microsoft to create my game. I currently have a main menu screen (GameScreen), a splash screen (Game Screen), high score screen (GameScreen), game play screen (GameScreen), and an options menu (MenuScreen). I have had my game running in the pre-production environment for around 48 hours. After switching between the main menu screen, splash screen, and highscore screen every five seconds for 36 or so hours the game performance really takes a hit and becomes unresponsive and the framerate drops to around 3fps.
Is there anyway to track this issue down in the GameStateManagement example. I have not made any changes to the base classes, I have just made child classes to add to the ScreenManager.
When I switch to a new screen I do this:
Main Menu to Splash Screen:
foreach (GameScreen screen in ScreenManager.GetScreens())
screen.ExitScreen();
ScreenManager.AddScreen(new SplashBackgroundScreen(), null);
ScreenManager.AddScreen(new SplashScreen(), null);
Splash Screen to Highscore Screen
foreach (GameScreen screen in ScreenManager.GetScreens())
screen.ExitScreen();
ScreenManager.AddScreen(new BackgroundScreen(), null);
ScreenManager.AddScreen(new HighScoreScreen(), null);
Highscore Screen back to Main Menu Screen
foreach (GameScreen screen in ScreenManager.GetScreens())
screen.ExitScreen();
ScreenManager.AddScreen(new BackgroundScreen(), null);
ScreenManager.AddScreen(new MainMenuScreen(), null);
I am running Windows 7 Home Premium x64 with 4GB of RAM on an Intel i3-2100 with Intel HD2000 graphics.
Are there any tools available to check for memory leaks in XNA. Are there any good tactics to start tracking down an issue like this? Would manually calling a garbage collection in the constructor of each game screen help?
EDIT
To clarify the above: In practice, what are the most efficient tools to find memory leaks relating to XNA?
The ScreenManager class keeps track of a stack of screens for the game, when you call ExitScreen it removes it from the stack.
ExitScreen() in GameScreen parent class:
public void ExitScreen()
{
if (TransitionOffTime == TimeSpan.Zero)
{
ScreenManager.RemoveScreen(this);
}
else
{
isExiting = true;
}
}
I don’t program XNA, but it looks like your causing a memory leak.
ScreenManager.GetScreens() seams to return an enumerable of GameScreen. Does screen.ExitScreen() remove the GameScreen reference from ScreenManager’s underlying collection of GameScreens?
Seems to me like your adding new instances
But never removing Exited / old / unused instances.
Perhaps you could add all your “GameScreen” instances to ScreenManager once at the beginning of your program and then hide/show just the “GameScreen”‘s you want on State Change events.