I’ve got a pretty big menu for my game and when I actually run my game I don’t want the menu’s resources to take up space in the physical memory. Additionally, I want to be able to “return” to the menu as many times as possible without filling up the memory.
I thought I’d solve this by
- creating a new instance of a menu and call method start(), like this: new menu().start().
- when the start method is finished, i.e. when the player presses “play”, the method will return a boolean.
- if the boolean is true a new game will be started, new Game().start() It too will return a boolean.
- if this boolean is true, branch to step 1.
This is my code:
public class SongsOfSyx {
private static GlMaster glManager;
private static PSettings settings;
public static void main(String[] args) {
glManager = new GlMaster();
settings = new PSettings();
if (true){ //args.length == 1
glManager.createDisplay("Launcher", new DisplayMode(GCONSTANTS.LAUNCHER_WIDTH,GCONSTANTS.LAUNCHER_HEIGHT), false);
if (new Launcher(settings).start()){
glManager.setSettings(settings);
loop();
}
glManager.cleanup();
}
}
private static void loop(){
while(true){
GameSpark gs = new MenuCore(glManager).start();
if (gs == null)
break;
if (!new GameCore(gs).start())
break;
}
}
}
I release all textures (using slick util) when returning from the start methods. However, when monitoring the task manager I can clearly see how each switch between the menu and the game increases the memory usage of the JVM with about 10mb, which is basically the space that my textures take up. Any ideas why the garabage-collector doesn’t take the hint?