StyleManager.ApplicationTheme memory leak?

2 posts, 0 answers
  1. Niko
    Niko avatar
    14 posts
    Member since:
    Jul 2012

    Posted 27 Sep 2013 Link to this post

    Hey guys,

    I have functionality to dynamically change themes via StyleManager.ApplicationTheme. Whenever the user changes themes, there is a roughly 20~30mb spike in memory usage that never seems to get garbage collected. Any idea on what would cause this?

    The following code is used to dynamically change the theme:
    public Theme ThisApplicationTheme
    {
       get { return StyleManager.ApplicationTheme; }
       set
       {
          StyleManager.ApplicationTheme = value;
          var binding = new Binding("ThisApplicationTheme") { Source = this, Mode = BindingMode.OneWay };
           foreach (Window window in Application.Current.Windows)
           {
                foreach (var element in GetWindow(window).ChildrenOfType<FrameworkElement>().ToList())
                {
                     element.SetBinding(StyleManager.ThemeProperty, binding);
                }
           }
           Application.Current.MainWindow.SetBinding(StyleManager.ThemeProperty, binding);
       }
    }

    Thanks.
  2. Pana
    Admin
    Pana avatar
    748 posts

    Posted 01 Oct 2013 Link to this post

    Hello,

    The bindings use a weak event manager that doesn't clear week event references immediately and when one of our themes is instantiated the XAML for the theme is parsed and the ResourceDictionary is cached.

    If you go from office black to office blue and then back and forth between these two themes a few times does the memory keep growing or at some point falls back?

    Besides we would like to point you to this article before proceeding with your application. This is the Telerik's recommended way to change themes at runtime.

    Regards,
    Pana
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top