A mitigation for a WPF memory leak
WPF (.net core and full .net) has a memory leak regarding using a font source with FontFamily. This is discussed in issue #746 from Material Design in Xaml Toolkit
This solution/mitigation is based on Dominic Jonas idea and adapted to be used/integrated by Material Design in Xaml Tookit.
To verify the issue open the full .net Demo and change the MainPage, Page1 and Page2 to use default font family sintax:
FontFamily="{DynamicResource MaterialDesignFont}"
Follow steps:
- Run it;
- Take a snapshot from Visual Studio Diagnostics Tool.
- Look form Unmanaged Resources. You find 101.
- Open Page 1;
- Take a snapshot from Visual Studio Diagnostics Tool.
- Look form Unmanaged Resources. You find 106.
- Open Page 2;
- Take a snapshot from Visual Studio Diagnostics Tool.
- Look form Unmanaged Resources. You find 110.
- Open Page 1 again;
- Take a snapshot from Visual Studio Diagnostics Tool.
- Look form Unmanaged Resources. You find 113.
Apply the fix in the MainPage, Page1 and Page2:
FontFamily="{customResources:FontResource FontName=Roboto}"
And redo the steps. You won't see the same problem.
MaterialDesignThemes.CustomResources