Possible Source of the Memory Errors

2GB Memory Windows Process Limit

When I started having game crashes I noticed a pattern in task manager. I believe that Windows has a 2 GB memory limit per process, so as the program reaches this limit, memory requests are being denied even if you have sufficient physical/virtual memory. I personally have 2 GB physical RAM and a 4 GB page file, but that's not the problem.

Under normal operating conditions, the program will rarely encounter this limitation (thus, why it occurs consistently for some people and not others). Playing larger maps with many planets and AIs increases the chance of this type of error. I think there were some possible bugs or memory leaks in the beta versions that were resolved, but the program still tends to increase memory usage over time; this explains the "I've been playing for two hours and then the game crashes" type of problem.

The tendency for GalCiv 2 to cache an enormous amount of data (3D textures or otherwise) is the root cause of this problem I think. The height maps alone have contributed as much as 400MB extra (~30% of total program memory usage on initial map load) on the 100% setting vs. 10% setting. The problem seems to have occured mainly with DA because of some features of the new engine or increased complexity in graphics/textures.

Although the program is prioritized for speed, much of what is loaded is not used regularly. I find about 50-60% of the memory being swapped back in during normal play. One solution is to unload certain data used seldomly (or only load it as needed). Another solution is to simply set the options so that less memory is used (this would be a user solution however; dynamically adjusting to stay under the 2GB limit is smarter). The memory used for saved games of large maps routinely starts at over 1 GB, easily reaches 1.5 GB, and eventually hits the 2 GB limit (and crashes). If this is the true cause of these recent problems, then it should be managable to fix.
8,860 views 14 replies
Reply #1 Top
Yep. I believe Cari's narrowed the excessive memory usage down to something not releasing ship textures, but exactly what it is doing that as yet remains a mystery (the memory leak checking program isn't turning anything up). If those textures were being released as they should, I'd imagine the game would have little trouble staying in the 2GB box.
Reply #2 Top
I have a memory problem. I have Vista and 3 Gigs of RAM. the 2 gig limit doesn't apply to Vista, as far as the operating system is concerned. I hope you developers didn't create this game to be compatible with Vista and only use 2 gigs max.

I have been getting not enough memory messages ever since the 1.6 beta 5 and especially since the final version came out. It has been working fine until now. My computer hasn't changed in 3-4 months so obviously something got changed that shouldn't have been changed in the game. I also play on a large map with 6 civilizations, (7 counting me). I don't mean to be rude but the beta was a lot better than the final release. Compared to the beta this final release has me thinking alpha. I'm not trying to diminish the game at all, I love it!!
But I just thought the testing would be over after the 1.6 final was released. AS it is, I can't even play it right now.

I could play the beta.
Reply #3 Top
Kyro, I do appreciate your team's attempts to fix these problems. GalCiv 2 is a very complex game, which makes this a particularly difficult fix. I was fairly certain that there was a leak that was graphics-related.

I've actually seen a reference (http://www.codinghorror.com/blog/archives/000811.html) that indicates that 1.5 GB is a more practical limit; It will always crash at 2 GB as a hard error, but the "out of memory" saving errors start at around 1.5 GB. Obviously the game shouldn't keep increasing memory usage over time in such a significant way. If what I'm seeing on the initial map load is all things preloaded, then the memory needs are actually as low as 800MB (quite reasonable).

One place where a leak might occur is in the DirectX engine itself. If you are caching textures in and out, it might be wiser to load everything once and expect the user to have the appropriate amount of virtual memory to support it. Using application-managed vs. system-managed textures can also contribute to this problem. Do you preload the textures when the map is loaded?
Reply #4 Top
I am also greatfull for the developers and this game. Although I realize that my reputation precedes me and what I am saying now doesn't carry any weight. I did not mean my post above (#2 reply) as an insult. Just that I was sad I'm having problems.

Also, I'll probably get banned for this....

Kyro.. why havn't I been banned yet? Heaven knows I deserve it. Not that I want to be. But I deserve it.

Reply #5 Top
One place where a leak might occur is in the DirectX engine itself. If you are caching textures in and out, it might be wiser to load everything once and expect the user to have the appropriate amount of virtual memory to support it. Using application-managed vs. system-managed textures can also contribute to this problem. Do you preload the textures when the map is loaded?


Those are Cari questions--I'm just the messenger
Reply #6 Top
There is definitely a memory leak with planetary invasions. I have all textures disabled on the lowest setting, but it still loads the planet surface texture. When it reaches memory limits, this texture becomes black as a silent error, then at that point I am guaranteed a save error.

If you leave the invasion screen open without attacking (the part where it is about to roll for combat), the memory usage will grow continously at several MB/s. There is no reason why this should occur unless it is reloading the texture over and over. It should be easy to replicate this behavior in your test lab.
Reply #8 Top
Thanks very much! It looks like you pulled of some Elf Magic here

I tried the patch and it looks like all problems have been resolved. Ship textures and models seem to be loading/unloading properly. Now I can turn on all the graphical effects again and play out some epic battles!
Reply #9 Top
Thanks very much! It looks like you pulled of some Elf Magic here


Thanks to you for finding the hint that led the way to it at last

*promotes Binary to Veteran*
Reply #10 Top
Very well done BinaryAlgorithm, you have saved the day. No doubt Stardock will be posting you a cheque forthwith.
Reply #11 Top
Nice work Binary well done! And thankyou to you too Cari, that build fixed all my problems as well

Reply #12 Top
After testing 1.6a for a time I realized that there is still a slow leak somewhere, although it's not as bad as before. While playing normally, memory usage is still increasing over time, but I notice that during colony management and on the main map it's fairly stable. As I perform massive numbers of invasions on a huge map, this is still the action that results in the highest increase in memory usage (although it's probably the combat textures, they are still in memory after the battle sequence from the look of it). I am assuming that memory usage should be roughly static after all basic game elements are loaded? Or perhaps you're just not expecting that much action to be taken on a map normally

I would also love an option to make ship movements instant for the player (like the AI ships move) because I have massive fleets that I have to wait for (15-20 min/turn sometimes), prohibiting me from building as many ships as I could support.

Many thanks for working on the code
Reply #13 Top
If your having a problem with memory leakage do you have to exit the game completely and come back in or can you just reload a save game form within the game?
Reply #14 Top
My experience is it's best to exit the game and restart. However, loading a game will free some of the resources, just not some of the leaked memory.