Each screenshot leaks about 7.9 MB of RAM at 1080p since ScreenshotCapture.SaveToPng never destroys its GenericTexture

Maxi

Member
Messages
219
Reaction score
171
Game Version
v2026.11.25.5949, base game.

Operating System
Windows 10 Pro 10.0.19045, NVIDIA GeForce RTX 5080 16 GB, 32 GB RAM.

What Happened
Each screenshot (PrintScreen or the terminal command screenshot) increases the private memory (commit size) of the game process by about the size of one RGBA8 picture (1920 x 1080 x 4 bytes = 7.9 MiB). The memory is never given back, also not after the game is left idle.

What Was Expected
The memory used to write a screenshot is freed after the PNG file is saved, so the commit size stays flat over many screenshots.

Reproduction Steps
  1. Start the game with only Core, windowed at 1920x1080, and load a flight (I used the Rocket on the pad CCSFS LC-39A).
  2. Open Task Manager, Details tab, and add the column "Commit size" for the game process.
  3. Wait until the value is stable, then press PrintScreen about 2 times per second for a few minutes (or run screenshot in the terminal many times).
  4. Watch the commit size grow by about 8 MB per screenshot, then wait a minute: it does not go down.
Reproduction Rate
Always (every screenshot).

Additional Info
Measured with Process.PrivateMemorySize64 of the game process (1 MiB = 1,048,576 bytes), 1920x1080 screenshots, 264 screenshots in about 3 minutes:
  • Before the first screenshot: 12,249.7 MiB. After 264 screenshots: 13,661.5 MiB. After 60 s more without input: 13,661.6 MiB (no drop).
  • Growth per step of 25 screenshots: 164 to 198 MiB, most steps 190 to 198 MiB, so 7.3 to 7.9 MiB per screenshot (one picture is 7.91 MiB).
  • Total growth 1,412 MiB. One step dropped by 407 MiB once (other memory of the game), and from that point to the end the growth was 1,152 MiB for 150 screenshots (7.7 MiB each).
Side note: the file name has a resolution of one second (ksa_yyyyMMdd_HHmmss_WxH.png), so two screenshots in the same second write the same file. 264 screenshots gave 149 files.

Technical analysis (decompiled 5949)
KSA.ScreenshotCapture.SaveToPng (runs in Task.Run after each capture) allocates a GenericTexture, writes it, and never calls Destroy():
Code
GenericTexture genericTexture = GenericTexture.Defaults.Uncompressed(TextureFormat.R8G8B8A8_UNorm, new int2(width, height));
pixelData.CopyTo(genericTexture.Data);
TextureWriter.SaveToFile(genericTexture, text);
In Brutal.TextureApi.Abstractions.GenericTexture the constructor allocates native memory, and only Destroy() frees it. The class has no finalizer and does not implement IDisposable, and TextureWriter.SaveToFile does not free the texture:
Code
_data = Mem.AllocZeroed(memAllocSize).Cast<byte>();
...
public void Destroy() { FreeData(); }
private unsafe void FreeData() { Mem.Free(_data); }
Suggested fix
Destroy the texture after the save, also when the save throws:
Code
GenericTexture genericTexture = GenericTexture.Defaults.Uncompressed(TextureFormat.R8G8B8A8_UNorm, new int2(width, height));
try { pixelData.CopyTo(genericTexture.Data); TextureWriter.SaveToFile(genericTexture, text); }
finally { genericTexture.Destroy(); }
Impact: a long series of screenshots, or a video capture that saves pictures frame by frame, fills the RAM (about 8 MB per 1080p picture, about 33 MB per 4K picture).
 
Upvote 1
Back
Top