[PR #1063] [MERGED] Use a ComPtr to avoid leaking font. #24466

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

📋 Pull Request Information

Original PR: https://github.com/microsoft/terminal/pull/1063
Author: @Robo210
Created: 5/30/2019
Status: Merged
Merged: 5/30/2019
Merged by: @undefined

Base: masterHead: fontmemleak


📝 Commits (1)

  • 7ede311 Use a ComPtr to avoid leaking font.

📊 Changes

1 file changed (+3 additions, -3 deletions)

View changed files

📝 src/renderer/dx/CustomTextLayout.cpp (+3 -3)

📄 Description

Summary of the Pull Request

Every screen update was causing memory usage to grow, seemingly unbounded. This appears to be due to a failure to decrement the reference count on a COM object.

References

PR Checklist

  • Closes Right click does not paste data copied from other apps (#768)
  • CLA signed. If not, go over here and sign the CLA
  • Tests added/passed
  • Requires documentation to be updated
  • I've discussed this with core contributors already. If not checked, I'm ready to accept this work might be rejected in favor of a different grand plan. Issue number where discussion took place: #xxx

Detailed Description of the Pull Request / Additional comments

The main allocation stack was:

Commit Stack Size (MB)
[Root] 3.609
ntdll.dll!RtlUserThreadStart 3.609
kernel32.dll!BaseThreadInitThunk 3.609
TerminalControl.dll!Microsoft::Console::Render::RenderThread::s_ThreadProc 3.609
TerminalControl.dll!Microsoft::Console::Render::Renderer::PaintFrame 3.609
TerminalControl.dll!Microsoft::Console::Render::Renderer::_PaintFrameForEngine 3.609
TerminalControl.dll!Microsoft::Console::Render::Renderer::_PaintBufferOutput 3.609
TerminalControl.dll!Microsoft::Console::Render::Renderer::_PaintBufferOutputHelper 3.609
TerminalControl.dll!Microsoft::Console::Render::DxEngine::PaintBufferLine 3.609
TerminalControl.dll!Microsoft::Console::Render::CustomTextLayout::_AnalyzeRuns 3.609
|- TerminalControl.dll!Microsoft::Console::Render::CustomTextLayout::_AnalyzeFontFallback 3.133
|    DWrite.dll!DWriteFontFallback::MapCharacters 3.133

DWriteFontFallback::MapCharacters was allocating a new IDWriteFont, but the COM object was never being released after it was used. Switching from a raw pointer to a ComPtr makes the leak no longer occur when, e.g., just scrolling up and down.


🔄 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/1063 **Author:** [@Robo210](https://github.com/Robo210) **Created:** 5/30/2019 **Status:** ✅ Merged **Merged:** 5/30/2019 **Merged by:** [@undefined](undefined) **Base:** `master` ← **Head:** `fontmemleak` --- ### 📝 Commits (1) - [`7ede311`](https://github.com/microsoft/terminal/commit/7ede311cefe4ef0cbb5334558280f42939d59272) Use a ComPtr to avoid leaking font. ### 📊 Changes **1 file changed** (+3 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `src/renderer/dx/CustomTextLayout.cpp` (+3 -3) </details> ### 📄 Description <!-- Enter a brief description/summary of your PR here. What does it fix/what does it change/how was it tested (even manually, if necessary)? --> ## Summary of the Pull Request Every screen update was causing memory usage to grow, seemingly unbounded. This appears to be due to a failure to decrement the reference count on a COM object. <!-- Other than the issue solved, is this relevant to any other issues/existing PRs? --> ## References <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist * [X] Closes #768 * [X] CLA signed. If not, go over [here](https://cla.opensource.microsoft.com/microsoft/Terminal) and sign the CLA * [ ] Tests added/passed * [ ] Requires documentation to be updated * [ ] I've discussed this with core contributors already. If not checked, I'm ready to accept this work might be rejected in favor of a different grand plan. Issue number where discussion took place: #xxx <!-- Provide a more detailed description of the PR, other things fixed or any additional comments/features here --> ## Detailed Description of the Pull Request / Additional comments The main allocation stack was: |Commit Stack | Size (MB)| |-- | --| [Root] | 3.609 ntdll.dll!RtlUserThreadStart | 3.609 kernel32.dll!BaseThreadInitThunk | 3.609 TerminalControl.dll!Microsoft::Console::Render::RenderThread::s_ThreadProc | 3.609 TerminalControl.dll!Microsoft::Console::Render::Renderer::PaintFrame | 3.609 TerminalControl.dll!Microsoft::Console::Render::Renderer::_PaintFrameForEngine | 3.609 TerminalControl.dll!Microsoft::Console::Render::Renderer::_PaintBufferOutput | 3.609 TerminalControl.dll!Microsoft::Console::Render::Renderer::_PaintBufferOutputHelper | 3.609 TerminalControl.dll!Microsoft::Console::Render::DxEngine::PaintBufferLine | 3.609 TerminalControl.dll!Microsoft::Console::Render::CustomTextLayout::_AnalyzeRuns | 3.609 \|- TerminalControl.dll!Microsoft::Console::Render::CustomTextLayout::_AnalyzeFontFallback | 3.133 \|    DWrite.dll!DWriteFontFallback::MapCharacters | 3.133 DWriteFontFallback::MapCharacters was allocating a new IDWriteFont, but the COM object was never being released after it was used. Switching from a raw pointer to a ComPtr makes the leak no longer occur when, e.g., just scrolling up and down. --- <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:03:28 +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#24466