Hard Light Productions Forums

Modding, Mission Design, and Coding => FS2 Open Coding - The Source Code Project (SCP) => Topic started by: Bobboau on February 16, 2004, 08:39:08 pm

Title: memory leaks
Post by: Bobboau on February 16, 2004, 08:39:08 pm
I'd like everyone who reads this to hit ctrl-alt-del, write down how much memory they are useing run FSO, write down how much they were usieng after and repete this sevral times, indicate in a responce on this topic how much memory you lost for each session and indicate how far into the game you played (ie did you play any mission if so how many, did you go to the tech room if so how many ships did you veiw, ect...)
were in the middle of some memory leak hunting right now, and I think this information would be useful
Title: memory leaks
Post by: taylor on February 16, 2004, 09:47:32 pm
I did a bunch of leak testing in Valgrind for the icculus.org version and the only big leak I found that wasn't *nix specific was with the talking heads.  The problem was that it keeps track of only the base type of anim to be played and not the a, b, c versions.  The anims would have multiple instances but with different data so the old data just got left around and never free()'d since the *p was replaced with that of the newly malloc()'d data.  Depending on the mission you could end up with about 15Megs or more of lost memory.

The fix is in two parts, part one is to see of the currently loaded message slot contains data and if so check the filenames to ensure they the same.  If they are different then run it through anim_free() before the new anim_load().  The second part is to keep going through anim_free() on mission shutdown the verify that all reference counts are properly handled and all data is free()'d.

Look here (http://cvs.icculus.org/horde/chora/diff.php/src/mission/missionmessage.cpp?rt=freespace2&r1=1.4&r2=1.5&ty=h) for a diff on the icculus.org CVS of what I added.  There may be a better way to handle this problem but after a lot of testing it was the only method I thought of that worked consistantly.
Title: memory leaks
Post by: CP5670 on February 16, 2004, 09:47:32 pm
How do you check the memory usage in 98 or Me? I have a program to check processor thread usage but not memory usage.
Title: memory leaks
Post by: Bobboau on February 16, 2004, 10:21:39 pm
I'm not sure..
and I'll try implementing that (crediting you)
Title: memory leaks
Post by: KARMA on February 17, 2004, 05:04:55 am
in w98se I have a resources measuring tool, which show 3 statistics: system resources, user's resources and GDI resources

I aslo have system monitor, which can show many indexes, like allocated memory, cpu usage, swapping, etc
Title: memory leaks
Post by: diamondgeezer on February 17, 2004, 11:18:20 am
CyberLat RAM Cleaner (http://www.ramcleaner.net/). Gives a handy realt-time read out of available RAM :nod:

I'll run some tests later on
Title: memory leaks
Post by: Turnsky on February 18, 2004, 03:36:56 am
the memory leak problems are so bad.. well lemme put it this way..

i have 256 mb of ram, and gave the page file 1 gb to play with...

"out of memory" errors..
Title: memory leaks
Post by: Bobboau on February 18, 2004, 08:08:33 am
well that isn't memory leaking that's memory useage, it's looking more and more like your going to need at least 512 megs of memory at the absolute minimum and a large pageing file
Title: memory leaks
Post by: RandomTiger on February 18, 2004, 12:19:42 pm
Quote
Originally posted by Bobboau
it's looking more and more like your going to need at least 512 megs of memory at the absolute minimum and a large pageing file


Even with the new builds? I dont think its that high with default data. If it is we will have to bring it down.
Title: memory leaks
Post by: Bobboau on February 18, 2004, 12:35:44 pm
it's that high with default data.

I load up the last mission and nearly 700 megs of ram is gobbled up (180 of wich was gone before I even started FS, so it's closer to 500)
Title: memory leaks
Post by: RandomTiger on February 18, 2004, 01:17:24 pm
Something is wrong then, I know weve upped limits but thats no excuse for a rise link that. Look at fs2's orginal requirements!
Title: memory leaks
Post by: CP5670 on February 18, 2004, 01:29:40 pm
Yeah, that's definitely way too high. The original FS2 used to require just 32mb; that is of course impossible now, but something like 192 or 256 would be more realistic.

DG: you have to pay for that though. Is there a free one somewhere?
Title: memory leaks
Post by: diamondgeezer on February 18, 2004, 01:49:33 pm
Quote
Originally posted by CP5670
DG: you have to pay for that though. Is there a free one somewhere?

Read it again - free trial with no time limit and very minor limitations

It'd slightly odd, but I actually have 50 or so MB more free RAM after exiting FSO than I did before I ran it...
Title: memory leaks
Post by: taylor on February 21, 2004, 02:31:12 am
Bobboau: I was updating with Linux code with the current CVS version and I noticed the one block of code for the memory leak in missionmessage.cpp was put in the wrong place.  This:
Code: [Select]
// free up remaining anim data
for (i=0; iif (Message_avis[i].anim_data != NULL) {
      for (j=0; jref_count; j++) {
         anim_free(Message_avis[i].anim_data);
      }
   }
   Message_avis[i].anim_data = NULL;
}

should be in message_mission_shutdown() rather than messages_init().  That data isn't accessible at the start of a mission.  I should have pointed that out a little better, sorry for the confusion.

For everyone else testing for memory leaks a good mission to try is the last one in the original campaign ("Apocalypse", sm3-10.fs2).  I believe that it contains most of the ship models in the game (28 of them), quite a few weapon types (at least 9), a lot of jump ins/outs (not going to bother counting), plays nearly all of the hud animations and I think it lasts for a good 20 minutes if not longer.  Plus it's got the strange ending which runs it through some different code.  I did most of my memory leak testing with this level under Linux.  Just an idea for those that are also looking for memory issues.
Title: memory leaks
Post by: CP5670 on February 22, 2004, 12:28:39 am
Quote
Read it again - free trial with no time limit and very minor limitations


oh, now I see what was happening. The download link is only in the popup that shows upon loading the website and I was closing it before it loaded, thinking it was just an ad.

Anyway, bobboau, what version of FS2 should I be testing? There are like ten different post-01_20_2004 exes floating around at the moment.

[edit] I tried out the 1_20_2004 one and it uses up around 280mb upon just running the exe. The numbers I gave earlier are probably far too high since it appears that almost no other game I have uses over 100mb at a time. Even the UT2004 demo appears to use only about 70mb. Considering that the original 1.2 uses something like 50mb, there is definitely a big problem here.

[edit2] I tried the build in the shinemap problems thread and that seems to be vastly improved; it's about 102mb now at startup. Whatever you did, it looks like it worked bigtime. :yes: I will post in-mission memory usage a bit later.
Title: memory leaks
Post by: taylor on March 04, 2004, 10:25:22 am
I posted a Valgrind log of the Linux version here (http://bellsouthpwp.net/m/t/mtrs/fs/vg-fso.txt).  Probably won't be much help to anyone but it's there for reference at least.  The Linux version uses about 250Meg (HT&L, DDS planets, 1024x768) on the high end, maybe up to 300Meg on with a really large mission, and may lose a few K between missions but it's kind of hard to measure that.  Please note that this log file is not with DDS planets since DevIL has a problem not freeing all memory when an image is closed, it's not the game in other words.

From the log though, the message_play_anim() problem is still there, that block of code listed earlier still needs to be moved into the shutdown function. wl_load_all_anims() is leaking a little but I'm pretty sure I fixed this in the icculus.org stuff so I'll go dig that code up.

There is some system lib stuff that should be ignored and few parse related leaks but those just aren't closed out properly on game shutdown rather than leaking in-game. Kind of the same thing with opengl_tcache_init().
Title: memory leaks
Post by: Fractux on March 04, 2004, 04:31:18 pm
This is just a repost of what I placed in the FPS thread. [ http://www.hard-light.net/forums/index.php/topic,20760.0.html ]



Quote


[....]

Oh yeah, and this is even with the -pcx32 flag turned off. (Which I was using for a while, but now leave off because it chews up some memory and, as you can see, I need all the memory I can get I only have 384MB RAM)

-pcx32 -jpgtga -htl -fps (-window : used to get memory use)(build 1-20-04)

1024x768 [D3D]
2xAA
4xAniso.
Best Quality (53.03 drivers)
using EAX (Fortissiomo II)

MEMORY VALUES ARE MINUS THE USAGE BEFORE STARTUP (120MB)

-STARTUP -> MAIN HALL: 282 (CPU usage at 80%)
-VISITED TECH ROOM [did not look at a different model] (CPU usage at 100%): 271
-EXITED TECH ROOM: 287 (CPU usage at 80%)
-Start Campaing: 490 (Homesick - Capella Capella)
-Committ Mission: 611 (CPU usage ~85-98%)
-Quit mission: 645
-Quit FS: 0 (back to 120MB)

....



Cheers!