Fix unbounded memory growth in the log view #185

Manually merged
github merged 1 commit from github-bot/gh-185 into gh-pr/185/base 2026-12-04 11:04:09 +00:00 AGit
Owner

@⁠Tuxeeee on GitHub · 2026-12-04 08:47 UTC · original
Tuxeeee:fix/log-undo-leak → main · +6 −0 · 1 files · 1 commits · merged 2026-12-04 10:52 UTC

Problem

The launcher's memory use climbs steadily while it runs and never comes back down. After a long session with the game running, I saw it at about 8 GB, with the game already closed.

AnsiLogBox derives from RichTextBox, and RichTextBox keeps undo history by default with no limit (IsUndoEnabled = true, UndoLimit = -1). Every AppendLines call runs inside BeginChange()/EndChange(), so each batch of log lines is stored as an undo unit. When the box trims old lines to stay under MaxChars/MaxLines, removing those paragraphs is recorded as an undo unit too, which keeps them alive. The visible log stays bounded, but everything ever written to it stays in memory.

Fix

Set IsUndoEnabled = false in the AnsiLogBox constructor. The log is read-only, so nothing uses undo. With undo off, trimmed paragraphs can be garbage-collected and the existing limits bound memory as intended.

Testing

  • Release build succeeds (dotnet build -c Release), no new warnings.
  • Not yet measured over a long session. The expected result is flat memory once the log reaches its line limit.

_logQueue and _nvidiaLogQueue in MainWindow are drained at most 80 lines per 50 ms tick, and nothing limits their size. Output faster than that (about 1,600 lines/s) piles up in the queues. That's a separate, smaller issue, left out to keep this change minimal.

**@⁠Tuxeeee** on GitHub · 2026-12-04 08:47 UTC · [original](https://github.com/isaac-btw/AmericasLauncher/pull/185) `Tuxeeee:fix/log-undo-leak` → `main` · +6 −0 · 1 files · 1 commits · merged 2026-12-04 10:52 UTC ## Problem The launcher's memory use climbs steadily while it runs and never comes back down. After a long session with the game running, I saw it at about 8 GB, with the game already closed. `AnsiLogBox` derives from `RichTextBox`, and `RichTextBox` keeps undo history by default with no limit (`IsUndoEnabled = true`, `UndoLimit = -1`). Every `AppendLines` call runs inside `BeginChange()`/`EndChange()`, so each batch of log lines is stored as an undo unit. When the box trims old lines to stay under `MaxChars`/`MaxLines`, removing those paragraphs is recorded as an undo unit too, which keeps them alive. The visible log stays bounded, but everything ever written to it stays in memory. ## Fix Set `IsUndoEnabled = false` in the `AnsiLogBox` constructor. The log is read-only, so nothing uses undo. With undo off, trimmed paragraphs can be garbage-collected and the existing limits bound memory as intended. ## Testing - Release build succeeds (`dotnet build -c Release`), no new warnings. - Not yet measured over a long session. The expected result is flat memory once the log reaches its line limit. ## Possibly related, not changed here `_logQueue` and `_nvidiaLogQueue` in `MainWindow` are drained at most 80 lines per 50 ms tick, and nothing limits their size. Output faster than that (about 1,600 lines/s) piles up in the queues. That's a separate, smaller issue, left out to keep this change minimal.
AnsiLogBox derives from RichTextBox, which keeps undo history by default
with no limit (UndoLimit -1). Each AppendLines batch became an undo unit
holding its paragraphs, and each trim kept the removed paragraphs alive
too, so the MaxChars/MaxLines bounds never released memory. Over a long
session with chatty child processes the launcher grew to several GB.

The log is read-only and needs no undo, so turn it off.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-04 08:50:16 +00:00
github-bot changed target branch from main to gh-pr/185/base 2026-12-04 11:04:02 +00:00
github manually merged commit 8ce0a2dddf into gh-pr/185/base 2026-12-04 11:04:09 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.