We are currently optimizing our first XNA game, we ran in into a problem:
There is a ScreenManager which manages all the screens. Every time we 'push' a new screen we remove (null) the old screen, so graphics should be removed from the memory. But it seems its not working, old graphics remain in the background. We are using this code to remove the previous screen:
private Screen RemoveScreen() {
Screen screen = (Screen)gameScreens.Peek();
OnScreenChange -= screen.ScreenChange;
Game.Components.Remove(screen);
screen.contentManager.Unload ();
return gameScreens.Pop();
}
We have done some research, and came across a possible solution to give every screen its own ContentManager. When we switch screens and nullify our old screen we run ContentManager.Unload() before we nullify it. Unfortunately its not working (old graphics remain being drawn, very weird flickering graphics). To clarify the problem i made this small youtube video, you can see the home screen, when i go the setting screen you can see the old homescreen while it should be removed: http://youtu.be/ii0qD6PusA8
I hope anyone can help us.