This is a migrated thread and some comments may be shown as answers.

StyleManager.ApplicationTheme memory leak?

1 Answer 94 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Niko
Top achievements
Rank 1
Niko asked on 27 Sep 2013, 06:32 PM
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.

1 Answer, 1 is accepted

Sort by
0
Pana
Telerik team
answered on 01 Oct 2013, 07:19 AM
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 >>
Tags
General Discussions
Asked by
Niko
Top achievements
Rank 1
Answers by
Pana
Telerik team
Share this question
or