wesnoth-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Wesnoth-dev] issues document


From: David White
Subject: Re: [Wesnoth-dev] issues document
Date: Sun, 18 Sep 2005 13:41:46 -0500
User-agent: Mozilla Thunderbird 0.8 (Windows/20040913)

ott wrote:

I did not found proof of any memory leak when running the game under valgrind's massif.

See the modified text in the version of the document in CVS, which notes
that the game uses lots of memory instead of discussing purported leaks.
I investigated why the game tends to take so much memory, and I think the main contributor is images. It might seem like the images we have aren't that large, but a 72x72 image = 5184 pixels, and we usually store with 4 bytes per pixel = around 20K. It is often less than this because we use RLE, and most images contain quite alot of transparency, but it's still probably at least 10K for most images.

Then, each image typically has the following:

- the base image, as loaded from disk
- the version for the current time of day (images + terrain)
- a greyed-out version (images + terrain)
- a brightened version
- reversed versions for each modified version of the image (we don't typically make reversed versions of the base image)

That's a total of seven. So, a single image might easily take 100K with all its copies. A typical type of unit, which might have 5 frames, could easily take 500K in memory. With all our types of units, one can easily imagine how 30+ megs of memory can be gobbled up in storing images.

Something else we should note: all the modified versions of images are flushed every time the time of day changes, since they are no longer valid for the new time of day. However, the base images are very rarely flushed: only when you type :refresh, or more likely, when you quit the game. We should probably consider changing this:

- in the short term, we could call flush_cache() a little more often, like when the user goes back to the title screen - in the longer term, we could have a maximum image cache size, and remove the least recently used image when it's filled up. This could be a compile-time setting and so builds for low-memory environments could have a smaller cache size.

I tried a little experiment: start the game, start Heir to the Throne, clicking 'next' on the storyline for the first scenario, to force it to load all the story images. Then clicked through the story so it showed all the portraits. By the time the first scenario had started, the Windows tasked memory reported 57 megabytes of usage. I then typed :refresh, and memory usage fell all the way to 35 megabytes, and then went back up modestly to 40 megabytes after having to reload the images necessary to redraw the current screen.

So while not technically a 'memory leak', any storyline images, the title screen, etc usually remain in memory until the game exits with our current scheme.

David




reply via email to

[Prev in Thread] Current Thread [Next in Thread]