Sign in to follow this  
Hyper Sonic

[.net] Resources are not being disposed when loading from a Windows Form

Recommended Posts

Hyper Sonic    136
Hi all. I'm having a problem I didn't notice until I tried my app in a box with ATI Rage XL video card with 8 MB in video memory. As much as I have read, most DirectX examples on the net call their DirectX form from the Main() function, so when the app ends, all resources are disposed because the program is completely destroyed. My DirectX app needs some configuration before being loaded, so I prompt the user to input game settings thru a Windows Form. When everything is ok, the user clicks on a Start button to begin my DirectX app. The code for this button is as follows:
try{
	using(MyGame game=new MyGame(GameSettings) ){
		try{
			game.Show();
			game.Run();
		}catch(Exception ex){
			MessageBox.Show("Error when running:\n- "+ex);
		}
	}
}catch(Exception ex){
	MessageBox.Show("Error when loading:\n- "+ex);
}

GC.Collect();


My original program uses a big RenderTarget (600x600) with a R5G6B5 Format and I know that this ATI card can only create this texture once. Trying to do it twice throws an OutOfVideoMemory exception. I dispose this texture at my DirectX form's Dispose method and I get back to my trigger form so everything is ok till this step. The problem comes when trying to begin my DirectX app again by clicking the Start button, I get an OutOfVideoMemoryException but Everything was supposed to be already disposed so I can't understand what is going on. I think this problem doesn't occur with my development machine because I have a much better card with 256 MB in video memory. I did a simple test with my machine. Instead of loading my DirectX app I created a simple DirectX app which only loads 14 low sized Pool.Managed textures. I'm already sure this simple app is disposing all textures. I watched Windows Task Manager Memory Usage column thru a coupe of runs. The results were the following: While Loader Windows Form is active and before doing first DirectX run: 17.9 MB During DirectX first run (a simple device + 14 small Managed textures): 35.048 MB After quitting DirectX first run (back to loader Windows Form): 31.416 MB (Shouldn't be 17.9 or closer??) During DirectX second run (the same app as first run): 35.508 MB After quitting DirectX second run (back to loader Windows Form): 34.504 MB During DirectX third run: 35.556 MB After quitting DirectX third run (back to loader Windows Form): 34.632 MB During DirectX fourth run: 35.604 MB After quitting DirectX fourth run (Back to loader Windows Form): 34.828 MB I really don't understand why the first DirectX run goes to 35 MB in memory and disposes only about 4 MB. Subsequent runs are more stable but memory usage is still going up after each run and this looks like a problem when using this application with old hardware. I think resources are not disposing properly, maybe my device or something else? The only solution I can figure out is to keep my DirectX app on a different Exe file and call it from my Windows Form so resources are released when the Exe file ends, but this requires me to Serialize/save/share my game settings thru both Exes and I think this is my last resource solution but I really want to find the appropriate solution. Any help will be greatly appreciated. Best Regards. [EDIT] I just did a new test, this time it's a simple DirectxX windows with no textures and no DirectSound, only an initialized device. During first run, memory is about 20 MB and never returns to 17 MB. Each subsequent run increases memory about 100 KB. [Edited by - Hyper Sonic on May 10, 2007 4:25:03 PM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this