Releasing resources

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

  1. creating a new instance of a menu and call method start(), like this: new menu().start().
  2. when the start method is finished, i.e. when the player presses “play”, the method will return a boolean.
  3. if the boolean is true a new game will be started, new Game().start() It too will return a boolean.
  4. 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?

Why should he? As long as the JVM got her space. You could request him with System.gc() but i wont recommend that.
And i wont recommend the task manager either but you could take a look into jvisualvm.

-ClaasJG

You might need to manually call Texture.dispose, because it is GL memory and not memory that will be collected by GC.

Thanks, I’ll look into a new taskmanager. Yes it seems the gc only collects trash when needed. I switched until I got to 200+MB and things started happening, great.

Its not a new Taskmanager.

[quote]Java VisualVM is an intuitive graphical user interface that provides detailed information about Java technology-based applications (Java applications) while they are running on a given Java Virtual Machine (JVM*). The name Java VisualVM comes from the fact that Java VisualVM provides information about the JVM software visually.
[/quote]
It comes with the normal jdk.

-ClaasJG