Force buffered sheets to commit data to a texture on buffer release.

Previously ReleaseBuffer did not immediately null out the buffer, instead the releaseBufferOnCommit flag allows it to be nulled when the texture is next access and the pending changes from the buffer are committed to it. Now the texture is committed immediately, thus the buffer is null once ReleaseBuffer returns.

Once loaded, we force a GC to reclaim temporary memory used during loading. Previously the buffer would not be null as it was pending commit to the texture and thus could not be reclaimed. As soon as we rendered the first frame, the buffer is nulled but we are now in a low GC state - and the buffer will not be reclaimed until the next gen 2 GC which may be dozens of minutes away.

This change ensures the buffer is null in time for the post-load GC, and thus can be reclaimed before we start rendering.
This commit is contained in:
RoosterDragon
2018-03-23 20:06:30 +00:00
committed by reaperrr
parent 83f100618b
commit 7bc5bd5791
2 changed files with 6 additions and 7 deletions

View File

@@ -153,6 +153,10 @@ namespace OpenRA.Graphics
return; return;
dirty = true; dirty = true;
releaseBufferOnCommit = true; releaseBufferOnCommit = true;
// Commit data from the buffer to the texture, allowing the buffer to be released and reclaimed by GC.
if (Game.Renderer != null)
GetTexture();
} }
public void Dispose() public void Dispose()

View File

@@ -276,13 +276,8 @@ namespace OpenRA
} }
} }
// The buffer is not fully reclaimed until changes are written out to the texture. // Release the buffer by forcing changes to be written out to the texture, allowing the buffer to be reclaimed by GC.
// We will access the texture in order to force changes to be written out, allowing the buffer to be freed. Game.RunAfterTick(sheetBuilder.Current.ReleaseBuffer);
Game.RunAfterTick(() =>
{
sheetBuilder.Current.ReleaseBuffer();
sheetBuilder.Current.GetTexture();
});
Log.Write("debug", "MapCache.LoadAsyncInternal ended"); Log.Write("debug", "MapCache.LoadAsyncInternal ended");
} }