python memory leak and video memory?

davidlallen

Deity
Joined
Apr 28, 2008
Messages
4,743
Location
California
I have been working in python for a couple of months. In the last few days I have been getting a lot of the sudden crash to desktop complaining that video memory is exhausted and I should lower my graphics resolution settings. I used to be able to view 11-player, 350 turn autoplay games on medium resolution fine. But in the last few days I run out of video memory on 5-player, lowest resolution. I have not added any units; recently I have changed gamefonts, added some flags, and added a lot of python code. I have not changed any hardware or other software like drivers. I have a large screen 1600x1050, but my concern is the *change* in behavior.

Something I have done, must have made the game use a lot more video memory, and it doesn't seem like any graphics changes are responsible.

Is it even *possible* to write bad python code which has memory leaks, which cause video memory to be exhausted? That does not sound right, but I am not a python expert.

Have other modders had this problem of video memory exhaustion suddenly getting *worse*? Anything I can try?
 
Is it even *possible* to write bad python code which has memory leaks, which cause video memory to be exhausted? That does not sound right, but I am not a python expert.
Garbage collected languages don't protect you from memory leaks; they just change the circumstances they happen in.

Most likely, you have something like this somewhere in the code:
Code:
A.member = B
B.member = A
That's it. A will never be deleted because it's referenced by B, and B will never be deleted because it's referenced by A.
I believe CPython has something that helps it deal with this somewhat, but I don't know how well it does so, or if it's in the version of Python being used. If I had to guess what was the problem though, that's it.
 
The message I am getting is specific to video memory:

Your system has run out of video memory. Please try reducing your video settings.

I will monitor the system memory available. Maybe I am using a lot, or a lot more than I used to. But it seems to me that python memory usage would give some other message rather than a video specific message.

Does anybody know of tools or debug settings that will help monitor for memory leaks in python running within the civ engine?
 
It's probably still the same problem: "B" is just an object on the map or something. (Video memory gets allocated from code, remember. ;)) Despite the fact that the object stops rendering, the memory itself is never released (either the reference problem above or a forgotten function call when an object is destroyed), so it just keeps building up until you run out.

I don't know any tools off the top of my head (I'm a C++ guy), but it might be as simple as combing through whatever code you added, find out what's new, etc. Maybe find an object that's being created by your new code and count the number of instances that are created versus the number that are destroyed; something like that.
 
After a little more investigation, I am inclined to blame the civfanatics banner ads. I often leave internet explorer running in the background while I play (somebody might post! :-). I have gotten a few message from explorer, complaining that some "movie file" is using a lot of memory. This has to be related to the civfanatics banner ads. I have done a few tests where I specifically don't leave explorer running while I play, and it seems fine.
 
Back
Top Bottom