OpenRA/OpenRA — pull request #6756 by RoosterDragon (2014-10-14 16:49:44+00:00)
Title: Release more sheet buffers

Followup to #5712 - releases more sheet buffers allowing 96 MiB of memory to be freed.

Some background for anybody unfamiliar: prior to #5712, the Sheet class would permanently hold a reference to a managed copy of the texture it was representing. This is for performance as making small incremental updates was faster than getting and setting texture data from the texture itself all the time. Instead the changes were batched up in the managed buffer and committed on demand to the texture.

#5712 introduced a method to allow this buffer to be marked for release once committed to the texture. If no more incremental updates are planned this allows the buffer memory to be reclaimed. This is important because these buffers can be very large.

Even after #5812 there were still some sheets with buffers that stuck around, allocated by:
MapCache (16m)
SpriteFont (16m)
VoxelLoader (16m)
SequenceCache * 4 (16m) (one per tileset)

This PR address 6 of those 7 sheets, freeing an additional 96 MiB.

The data buffer is now generated lazily, which solves the problem for VoxelLoader.
The 4 SequenceCache sheets are released as part of preloading the sequences - when preloading everything we know we won't be needing the buffer again later.
The MapCache sheet is now released when the map generation thread dies. In this particular case the texture may not get rendered for a while, so we make a manual call to force the buffer to be written to the texture after which it can be freed.

This only leaves a buffer for the SpriteFont sheet. When text is drawn the glyphs are lazily generated and so we can't easily get rid of the buffer without impacting either performance or flexibility.