XNAゲームでスクリーンショットを作成すると、それぞれがtexture.SaveAsPngある程度のメモリを消費し、ゲームに戻らないようです。だから結局私はメモリを使い果たします。テクスチャデータをFileStreamとMemoryStreamに保存してみましたが、そこからとして保存できることを期待してBitmap、結果は同じです。このメモリを強制的に解放する方法や、メモリ不足の例外が発生することなく画像データを取得して別の方法で保存できる回避策はありますか?
sw = GraphicsDevice.Viewport.Width;
sh = GraphicsDevice.Viewport.Height;
int[] backBuffer = new int[sw * sh];
GraphicsDevice.GetBackBufferData(backBuffer);
using(Texture2D texture = new Texture2D(GraphicsDevice, sw, sh, false,
GraphicsDevice.PresentationParameters.BackBufferFormat))
{
texture.SetData(backBuffer);
using(var fs = new FileStream("screenshot.png", FileMode.Create))
texture.SaveAsPng(fs, sw, sh); // ← this line causes memory leak
}