-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Using a font resource with FontFamily will cause UnmanagedMemoryStream leaks #746
Comments
@ButchersBoy I know you've got a lot on your plate but if you think this is a good idea I can provide a PR:
I would also add some info about this behaviour in the wiki. Or I could just provide the info in the wiki. |
Yes, good idea, so long as we keep all the existing stuff in tact as you have said. |
I have put in a "fix" for this that I am looking to get feedback on. It is an opt-in style feature. TextElement.FontFamily="{x:Static wpf:MaterialDesignFonts.Roboto}" Now there are a couple things worth considering here:
|
Nice work! I like it. It is simple and we can expand on it if we have to. Keep it! |
Have you seen this different solution: using a markup extension to fix memory leak With this:
|
@quicoli I have not seen that. I think I like it better, though I think i am going to leave in the option for people to include the font files in their project if they want. I dropped the |
I'll create a package with this resource implementation so who can't update
to the future version can at least have a fix.
See you
…On Sun, Dec 8, 2019, 07:33 Kevin B ***@***.***> wrote:
@quicoli <https://github.com/quicoli> I have not seen that. I think I
like it better, though I think i am going to leave in the option for people
to include the font files in their project if they want. I dropped the
MaterialDesignFonts static class in favor of the MaterialDesignFont
markup extension.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#746?email_source=notifications&email_token=AB775D4OYM2HEUJRIHZMBPTQXSPLVA5CNFSM4DSVHSMKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEGGX2AA#issuecomment-562920704>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AB775D5HB6672TGTMBKPBCDQXSPLVANCNFSM4DSVHSMA>
.
|
* Fixes MaterialDesignInXAML#746 Allowing the option for projects to opt-into having the font files copied locally rather than used as an embedded resource. No longer setting font for DailogHost No longer setting font for Toolbar. * Icons update from Azure pipeline (MaterialDesignInXAML#1534) * Cleanup pipeline (MaterialDesignInXAML#1538) * WIP cleaning up build pipeline since we no longer need AppVeyor. * Parameterizing the nuget to make local builds easier. * Fixing license url Fixing framework dependency groups * Script and nuspec updates to handle the icons * Fixing dependency group * Moving build script and adding all NuGets * Adding netcore target to nuget package. * Adding default dependency group * Updating build pipeline to build NuGet packages. * Update azure-pipelines.yml for Azure Pipelines * Update azure-pipelines.yml for Azure Pipelines * Update azure-pipelines.yml for Azure Pipelines * Update azure-pipelines.yml for Azure Pipelines * Update azure-pipelines.yml for Azure Pipelines * Fixing TextAlignment for NumericUpDown control (MaterialDesignInXAML#1540) * Change Calendar TodayBackground to Transparent with a circle around it (MaterialDesignInXAML#1446) * Change Calendar TodayBackground to SecondaryAccentBrush * Update Current date to a Transparent circle with black border like in https://material.io/components/pickers/ * Change TodayBackground Stroke color to Foreground color * Fix the text for current date is always black * Default IsMonitoring to true (MaterialDesignInXAML#1541) This is needed for MahApps attached properties to register for events to respond to things like SelectAllOnFocus. Fixes MaterialDesignInXAML#1539 * Filled and Outlined DatePicker styles (MaterialDesignInXAML#1501) * Filled and Outlined DatePicker styles * Removed redundant setter * Forward attached properites Inherited attached properties can have performance implications. So instead we simply forward them as needed. * Icons update from Azure pipeline (MaterialDesignInXAML#1544) * Custom Thumb Control and ControlTemplate to fix issue MaterialDesignInXAML#1531 (MaterialDesignInXAML#1542) * Created Custom Thumb to override the cursor when dragging. Created ControlTemplate for Thumb that sets cursor to SizeWE * Implemented code review suggested changes GridViewColumnThumb is now internal. Created a new style explicitly for the GridView Column. GridViewColumnHeader now uses this new style. * Fixed foreground brush on Light, Dark and Accent versions of CheckBox and RadioButton styles (MaterialDesignInXAML#1543) * Fixing the underline behavior of the numeric up down control (MaterialDesignInXAML#1547) * Fixing nuget minor version. (MaterialDesignInXAML#1548) * Another attempted fix for MaterialDesignInXAML#746 * Updating demo to use the markup extension * Renaming file to match class name
I just published a nuget package for this. |
Background
This is a known WPF issue but still affects applications created with Material Design XAML Toolkit since it relies on the Roboto font. See https://stackoverflow.com/a/31452979. The answer at StackOverflow has a broken link to a issue at Microsoft Connect. I have not been able to find out if this bug is going to be fixed. I have not found any official comments about this issue.
According to my observations the leaked object
UnmanagedMemoryStream
is very small in size, about 32 bytes. This makes it almost invisible to the memory footprint of many applications. I observed this leak in an application with many bindings which are updated frequently. The application is not expected to be restarted often. These traits would lead to huge amounts ofUnmanagedMemoryStream
being created over time.How to reproduce
You need Visual Studio Diagnostics Tool, dotMemory or another memory profiler to observer the memory leak. I have used both Visual Studio Diagnostics Tool and dotMemory to track down the leak and confirm it has to do with font loading.
Visual Studio Diagnostics Tool
UnmanagedMemoryStream
UnmanagedMemoryStream
UnmanagedMemoryStream
Workaround
The workaround suggested by Israel Altar is to use file based fonts instead of resource based fonts. I have confirmed that this workaround "works on my machine".
FontFamily
instance:Add the fonts with "Build Action"
None
and "Copy to Output Directory"Copy if newer
FontFamily
attributes on yourWindow
types. This is the only place I use the Roboto font in my application:Future
How do we handle this issue in Material Design XAML Toolkit? Possible actions below but I let you guys weigh in on the way forward.
MaterialDesignFonts
type that takes care of writing temporary font files to disk before loading{StaticResource MaterialDesignFont}
or{x:Static materialDesign:MaterialDesignFonts.Roboto}
Personally I think it would be nice if I could use the material design fonts without memory leakage out of the box :)
The text was updated successfully, but these errors were encountered: