Game Development Community

Oops, using a lot of RAM

by Philip Mansfield · in Torque Game Builder · 06/14/2005 (3:47 am) · 33 replies

I don't profess to be a great coder, but I wasn't expecting my (so far) relatively simple game to take up about 100MB RAM.

This leads me to believe that my graphics and sounds are all loaded as soon they are defined in a datablock. If I knock out some of the datablocks, then the RAM usage decreases a little.

I'm going to experiment with my art and seeing if reducing the resolution of it will impact on it's final appearance, but a better solution would be a way of unloading graphics that I don't need any more.

The loading of the graphics can be split out (menugfx.cs, lvl1gfx.cs, lvl2gfx and so-on) with each section of the game able to load its own assets. It's just how to unload them afterwards that I'm not sure about.

The same needs to apply to sound effects. I can set the preload to false and this saves some more RAM, but it would be nice to be able to unload sound effects that I don't need for the next level.

I'm not looking to get things down to the absolute minimum, but I just thought that 90-100MB of RAM was a little excessive for what I was actually doing.
Page «Previous 1 2
#1
06/16/2005 (4:02 am)
*Bump*

No takers on improving memory management with T2D?
#2
06/16/2005 (9:51 am)
I have not tried this yet, but can you not just call delete on the imageblock identifier?


// set up the enemydatablock fxImageMapDatablock2D(enemyship1ImageMap)
{
mode = full;
textureName = "~/client/images/enemyship1";
};



delete enemyship1ImageMap;
#3
06/16/2005 (12:01 pm)
Try this:

echo("[Debug] Start Test");

echo("[Debug] Create Image Map");
// Load asteroids.png
datablock fxImageMapDatablock2D(testImageMap)
{
mode = full;
textureName = "~/client/images/asteroids";
};

echo("[Debug] Create Sprite");
%testObj = new fxStaticSprite2D() { scenegraph = t2dSceneGraph; };
%testObj.setSize("10 5");
%testObj.setPosition("0 0");
%testObj.setImageMap(testImageMap);

echo("[Debug] Delete Sprite");
%testObj.safeDelete();

echo("[Debug] Delete Image Map");
testImageMap.delete();

echo("[Debug] Test Finished");


It runs without errors, so I am assuming that the delete function will free the memory it has allocated.
#4
06/17/2005 (3:08 am)
Hmm, doesn't seem to make a huge amount of difference, but I probably need to restructure my code a bit.

Time to look into Simsets I think... :)
#5
08/09/2005 (4:13 pm)
My game is using a ton of RAM, too: nearly 120MB. But there is a lot of art. Still, it never seems to go down, and it climbs slowly the longer the game runs. I've looked at the only places where I'm allocating objects and they are getting deleted because they report debug info in onRemove() calls. I guess it's a leak somewhere, but there are no obvious tools for tracking such things so it's trial and error. :(

I have no idea how Torque manages memory. Does it use pools? Does it free allocations when the script objects are deleted or is that deferred to some garbage collection run? Anybody know?
#6
08/09/2005 (7:27 pm)
Is there any way to show the current allocations from script? How do most people debug memory leaks with TorqueScript?
#7
08/09/2005 (8:17 pm)
Well I checked my pinball game and my memory usage goes form 133,000 base to 204,000 for the game..
so I went over to gold fever and loaded that and that one loaded up at 304,000 usage.. so I dont know if T2D is just a memory hog or what.. :)


*and its in bytes..

so my game uses about 71 mbs..
and gold fever uses about 171 mbs..
#8
08/09/2005 (9:09 pm)
I suppose it must expand based on system resources..? So I can't tell if I'm leaking memory or if it's just Torque's allocation method increasing some pool size, etc. More internal details would be nice to know.

Thanks for the info, Tom.
#9
08/09/2005 (9:36 pm)
After some more observation, I think what's happening is that Torque is caching all the sounds and art that gets used, as it gets used. I guess on a more constrained system than mine (512MB RAM) it would not cache as much stuff. So the memory footprint does indeed expand as the game progresses, but not necessarily from a memory leak. Since it will hold everything in RAM that will fit, it appears that nothing is being deallocated, but I noticed that the RAM use peaked until a new sound or effect was used, then it would go up a bit but hold there.

I think that's what's happening, but it's pure conjecture. :)
#10
08/09/2005 (10:16 pm)
I read about some functions to clear the cache that were in TGE, unless they were removed for T2D.
#11
08/16/2005 (12:37 pm)
One big thing that wil bloat your program size is the console. As text shoots out to the console at a rapid clip (especially with complex code running in a rapidly scheduled call, the console can rack up 10, 20, 30 extra MBs of RAM easy.

A solution to this is to either turn off the console (which you'll do upon release of the app), or run the cls() function every now and again to clear the console and get rid of all those extra characters taking up memory.

That's what I do anways. It helps a LOT.
#12
10/20/2005 (10:43 am)
I tried what Bryan said and didn't change that much, i probably got 20kb or so.
(I was not hoping for a miracle. ;) )

I do find weird that a game wish two small sized graphics will take 30mb, im guessing this is because of the t2d sub-systems (eg: gui).
#13
10/20/2005 (11:11 am)
The aquarium T2D demo on a 1Gb RAM machine takes about 600Mb of memory on one run, then about 500Mb on the second run...
#14
10/20/2005 (6:43 pm)
Well, that's interesting. It only takes 20mb on this development computer (that has 256mb, no low performance and i had several programs running).
I believe now that it uses a % of the available memory for best performance without actually hitting the overall system performance. Feel free to correct me if im wrong.
#15
04/18/2006 (1:12 am)
I just ran into trouble with this today. 1.2 gb from less than 57mb of images. What is going on here?

This isn't for a game I am working on. This is for a game that a game company is making using TGB and they are incredibly shocked and I am really embaressed. The game is complete and ready to release but now there is this crazy 1.2 gb of ram usage problem that appears to be a part of the game engine design. I am defending GG for selling a commercial license for something that isn't complete. Of course... buyer beware... but in the real world I am grasping at straws trying to keep a positive spin on this.

I hope that someone knows something about what is going on with this because I'd really like for this to end well for them. I hope someone who knows something catches this thread and let's us in on how to fix this. Games are being made professionally with TGB and it's only in the best interest of GG and TGB to fix these problems so that more licenses can be sold and GG and TGB technology can be the best solution for 2D game development.
#16
04/18/2006 (7:53 am)
Of course GG wants to fix all problems, if I could presume to speak for them!
Quote:I am defending GG for selling a commercial license for something that isn't complete.

T2D - TGB has alpha, beta, "early adopter" stamped all over it! what's unclear about that? Here is what I would do if I were you:

1. make sure they are using the latest BETA (new stuff coming out every couple of weeks now it seems with lots of bug fixes)

2. debug. i.e. start commenting out exec() in your scripts to isolate the module or art asset where the ram is getting used up. you know it's not in the T2D engine with a plain level.


3. read Image Maps.pdf for instruction how to hook into the image packing routines and see exactly what's going on with the images .

4. maybe it's just a programming bug unrelated to image packing? 2. will help isolate that right away.
#17
04/18/2006 (8:10 am)
@Anton -more thoughts... there are handful (not many) similar threads in the forums, for both TGE and T2D. Here are some solutions to similar threads

- user was calling audio playing functions incorrectly so Torque was loading uncompressed .mp3 data into memory (Gigs worth)

- Melv says image packing in T2D 1.0.2 was not correct, so use a newer version of T2D.

- long inconclusive thread about virtual memory settings on Windows, what it means, how much the game should be allowed to "reserve"

Of course using the site for "memory usage" or something like that you will get more ideas.
#18
04/18/2006 (9:58 am)
I just brought up task manager on a couple of games I am working on. One of the games could probably ship today and the other one is also pretty complete except for gameplay difficulty issues. In other words, both have complete sfx/art content being used - they're not small prototypes.

The machine I tested on has 1 Gig ram. Memory usage was 50 mb for one game and 87 Mb for the other. I ran for a while and went through all the different screens.
#19
04/18/2006 (11:59 am)
@Kevin are you using maps?
big tilemaps seems to use huge memory for me.
#20
04/18/2006 (12:47 pm)
I would take a look at the particle emitters and explosions. There are fixes for a few leaks in them in the TGE forums that we had encountered once before. That should remove the problem of the memory footprint ever increasing. At least it did for us in TGE, I haven't had T2D long enough to implement the fix again yet.

www.garagegames.com/mg/forums/result.thread.php?qt=38472
Page «Previous 1 2