Fix FontSource/FontFileStream embedded resource memory leak#9948
Conversation
❤️❤️❤️ |
|
LGTM |
|
What is the status of this issue? Anyfix soon? |
|
@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:
|
|
Thank you @h3xds1nz for your continuous contributions! 😄 |
|
@himgoyalmicro Thank you, maybe I'll fix some more stuff then 😀 |
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():UnmanagedMemoryStreaminstance, but life without destructor is kind of hard.FontFileStreamfromDirectWriteForwarderwould be migrated to C#.More context: The fix could be done by disposing the
UnmanagedMemoryStreaminstantly and wrapping it in a new instance so it's cleared from theList<Stream>ofPackagePartbut 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