Release UnmanagedMemoryStream Resources
Environment
Product | Telerik UI for WPF |
---|---|
Version | 2023.3.1010 |
Description
UnmanagedMemoryStream
objects are stacking up in memory and never released on refresh of Telerik controls. For example, when resetting the ItemsSource of RadGridView. The issues occurs in newer Telerik themes - Material and later.
This happens because of a memory leak in WPF. In the Telerik's context this manifests when using the RadGlyph controls, which registers the custom Telerik font (TelerikWebUI) which holds the glyph icons.
Solution
To prevent the memory leak, unregister the TelerikWebUI font using the RadGlyph API and then re-register again in the App class. Make sure to use the absolute path to the .ttf file when registering the font.
public App()
{
var glyphType = typeof(RadGlyph);
var unregisterMethod = glyphType.GetMethod("UnregisterFont", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic);
unregisterMethod.Invoke(null, new object[1] { "TelerikWebUI" });
ParserContext parserContext = new ParserContext();
parserContext.XmlnsDictionary.Add("", "http://schemas.microsoft.com/winfx/2006/xaml/presentation");
parserContext.XmlnsDictionary.Add("x", "http://schemas.microsoft.com/winfx/2006/xaml");
string processDirPath = System.IO.Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
string projectRootDir = System.IO.Path.GetFullPath(processDirPath + @"......");
var telerikFontString = string.Format("<FontFamily>{0}\TelerikWebUI.ttf#TelerikWebUI</FontFamily>", projectRootDir);
var telerikFont = (FontFamily)System.Windows.Markup.XamlReader.Parse(telerikFontString, parserContext);
RadGlyph.RegisterFont(telerikFont, "TelerikWebUI");
}
\Core\Controls\Themes\Fonts\old\TelerikWebUI.ttf