Game Development Community

Memory Leak In Torque GUI?

by Matthew Hoesterey · in Torque X 2D · 03/10/2009 (9:53 pm) · 12 replies

I've accidentally discovered a performance problem yesterday. If I leave my game idle for a few minutes on my main menu my memory slowly gets sucked away. Once my level is loaded the memory leak stops though the leaked memory can not be recovered and will cause performance problems.

In an attempt to isolate the problem I actually ripped out all my menu code and just included a GUI Splash screen that waits about 4 min before fading out and loading the level and found that the leak still exists

Has anyone experienced the same issue when leaving your menu idle for a few min?

there might be a bug in my code but I'm running out of places to look.

Also has anyone got the CLR Profiler working with torque? for some reason I can't get the program to work.

Thanks for any help :)

#1
03/11/2009 (7:02 pm)
This happens to me also. If I have my main menu on screen then memory slowly gets taken up. Hmm.
#2
03/11/2009 (7:22 pm)
Have you gotten the CLR Profiler to work with torque? It crashes for me.

I'm not sure how to find this one without it as I'm beginning to think it's an engine level problem.

I wish there was someone to talk to from Garage Games to see if they are aware of this problem but I'm not sure how to contact them short of paying 250 bucks an hour for tech support. I'm not quite ready to do that.

I'm going to investigate further let me know if you find anything.
#3
03/13/2009 (6:56 am)
I tested XNA Chopper Strike by increasing the splash screen wait time to 4 min. There is a HUGE memory leak in it. I also tried waiting at the main menu and got the same results.


You can display the memory used on screen by updating text with the following code every tick

_leak.Text = System.GC.GetTotalMemory(true).ToString();


You'll notice if you quickly move through the menues this number will fluctuate but stay around 5,311,760 as you play

If you wait for a few min at a gui screen before entering the game this number will become bigger the longer you wait. Waiting 4 min the new number over doubled.

On xbox this leak causes even chopper strike to slow to a crawl. I'll open a bug and see if I can get some info on this.
#4
03/13/2009 (10:42 am)
GG got back to me. They added this bug as a ticket and are looking into it. :)
#5
03/13/2009 (1:47 pm)
Hey Matthew,

Great find, this will be very helpful for the rest of us :)

- Alex

www.stinkerstudios.com
#6
03/13/2009 (6:45 pm)
Thanks man!
#7
03/18/2009 (9:08 pm)
I just ran the test suggested by Matthew on my game and I don't seem to be having this problem.

I used the FPS demo as a template for setting up my menus and not the GUI stuff from the TX Book so it's possible that there is some slight difference in the two methods that accounts for this.

I'm not currently using a splash screen as I don't want to look at it every time I load the game for testing so it's also possible the leak in in the GUI Splash part of things. Anyway, you guys might give the FPS demo that came with TX a look to see if that clears up your problems.
#8
03/19/2009 (7:47 am)
Heya Sean. Correct me if I'm wrong. But I belive the FPS demo uses a Popup GUI method that you bring up during gameplay. I'm using that in my game too without a problem.

The leak is in GUI methods that are loaded before the .txscene. So if you load splash or a GUIBitmap class as your main menu you will probably see this problem.
#9
03/19/2009 (8:31 am)
@Matthew

You're correct about the FPS demo using a popup. I don't think the problem is with GUIBitmap as the base of the FPS demo popup is a GUIBitmap.

What I've been doing is just using the popup for all of my menus and just resizing it to fill the screen. So my main menu is a full screen popup displayed over an empty txscene.

I'll try adding a splash screen this evening to see what happens. If the GUISplash stuff is causing leaks maybe you could make a "splash screen scene" that displays your splash images and then loads the menu.
#10
03/19/2009 (4:30 pm)
Heya Sean. I don't think it's the splash.

I tried removing that and got the same problem.

I havn't tried loading a blank .txscene though.

I think the leak only happens if you don't have a .txscene loaded yet and stops when you do. Not sure where it is though :).

I'll try that out and post the results.
#11
05/25/2009 (1:45 pm)
I tried loading a .txscene in my game class before loading the menus. Sadly this leak is still present. I believe it is in the GUI classes though I'm not sure.
#12
05/27/2009 (9:52 am)
The sollution was found by: Lucas Shinkovich

Inside GarageGames.Torque.GUI.DrawUtil on line 362 replace the following:

RenderInstance ri = SceneRenderer.RenderManager.AllocateInstance();

with

RenderInstance ri = new RenderInstance();


It seems to have worked for me. Hopefully someone who knows more about Torque X can verify that this change will not effect anything else.