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

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

📋 Pull Request Information

Original PR: https://github.com/microsoft/terminal/pull/10738
Author: @lhecker
Created: 7/20/2021
Status: Merged
Merged: 7/21/2021
Merged by: @undefined

Base: mainHead: dev/lhecker/server-memory-limit


📝 Commits (1)

  • e023dfa Release unneeded memory more eagerly from conhost

📊 Changes

2 files changed (+24 additions, -2 deletions)

View changed files

📝 src/inc/til/u8u16convert.h (+8 -0)
📝 src/server/ApiMessage.cpp (+16 -2)

📄 Description

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 ✔️

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/microsoft/terminal/pull/10738 **Author:** [@lhecker](https://github.com/lhecker) **Created:** 7/20/2021 **Status:** ✅ Merged **Merged:** 7/21/2021 **Merged by:** [@undefined](undefined) **Base:** `main` ← **Head:** `dev/lhecker/server-memory-limit` --- ### 📝 Commits (1) - [`e023dfa`](https://github.com/microsoft/terminal/commit/e023dfa83068fd45ddbad644c148652a13daa76d) Release unneeded memory more eagerly from conhost ### 📊 Changes **2 files changed** (+24 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `src/inc/til/u8u16convert.h` (+8 -0) 📝 `src/server/ApiMessage.cpp` (+16 -2) </details> ### 📄 Description 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 ✔️ --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-31 09:27:01 +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#28207