[PR #10738] Release unneeded memory more eagerly from conhost #28212

Open
opened 2026-01-31 09:27:02 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/microsoft/terminal/pull/10738

State: closed
Merged: Yes


The _CONSOLE_API_MSG buffer is resized to cover an entire message.
Later on any UTF-8 data is cached in a separate temporary
buffer inside til::u8state to prevent lone surrogate pairs.

Both cases are problematic as neither buffer is freed after the read
has finished. Passing a 100MB buffer to conhost once will thus cause it
to continue using ~220MB of physical memory until the conhost process exits.

This change releases unneeded memory as soon as the requested buffer
size has halved. In practice this means that once a command has returned
all buffers will shrink, as the shell commonly sends very small messages.

PR Checklist

Validation Steps Performed

  • Buffers aren't reallocated during printing ✔️
  • Buffers shrink after printing finished ✔️
**Original Pull Request:** https://github.com/microsoft/terminal/pull/10738 **State:** closed **Merged:** Yes --- The `_CONSOLE_API_MSG` buffer is resized to cover an entire message. Later on any UTF-8 data is cached in a separate temporary buffer inside `til::u8state` to prevent lone surrogate pairs. Both cases are problematic as neither buffer is freed after the read has finished. Passing a 100MB buffer to conhost once will thus cause it to continue using ~220MB of physical memory until the conhost process exits. This change releases unneeded memory as soon as the requested buffer size has halved. In practice this means that once a command has returned all buffers will shrink, as the shell commonly sends very small messages. ## PR Checklist * [x] Closes #10731 * [x] I work here * [x] Tests added/passed ## Validation Steps Performed * Buffers aren't reallocated during printing ✔️ * Buffers shrink after printing finished ✔️
claunia added the pull-request label 2026-01-31 09:27:02 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#28212