-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix FontSource/FontFileStream embedded resource memory leak #9948
base: main
Are you sure you want to change the base?
Conversation
❤️❤️❤️ |
src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/FontCache/FontSource.cs
Show resolved
Hide resolved
src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/FontCache/FontSource.cs
Outdated
Show resolved
Hide resolved
LGTM |
What is the status of this issue? Anyfix soon? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@h3xds1nz this PR is good to be merged. Can you please resolve the merge conflicts and the conversations. |
64a136f
to
fbaf8b5
Compare
@himgoyalmicro Resolved :) P.S. I'd consider backporting this to NetFX given that you've backported the XPS one as well. For some apps this is rather a big issue. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #9948 +/- ##
===================================================
- Coverage 11.55182% 11.41724% -0.13458%
===================================================
Files 3214 3214
Lines 648495 648502 +7
Branches 71512 71510 -2
===================================================
- Hits 74913 74041 -872
- Misses 572419 573303 +884
+ Partials 1163 1158 -5
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
Fixes #7289
Description
Fixes memory leak when using fonts from embedded resources that are materialized onto
FontSource
->FontFamily
, etc.The issue is basically in
FontSource.GetUnmanagedStream()
:UnmanagedMemoryStream
instance, but life without destructor is kind of hard.FontFileStream
fromDirectWriteForwarder
would be migrated to C#.More context: The fix could be done by disposing the
UnmanagedMemoryStream
instantly and wrapping it in a new instance so it's cleared from theList<Stream>
ofPackagePart
but I think it's nice to tie the lifetime together.Customer Impact
Customers will finally get their fix after 10 years.
https://stackoverflow.com/questions/31452443/wpf-textblock-memory-leak-when-using-font
https://stackoverflow.com/questions/49550759/wpf-load-font-from-resources
https://stackoverflow.com/questions/45297837/what-causes-unmanagedmemorystream-in-wpf-memory-leak
https://stackoverflow.com/questions/39157846/wpf-glyphs-control-font-uriits-slow-and-remains-in-memory
Regression
Has been around since at least .NET 4.5.
Testing
Using the repro in #7289; sample apps use.
Risk
Low though we're passing around stuff onto C++/CLI, that's always awful.
Microsoft Reviewers: Open in CodeFlow