Skip to content

RangeSlider memory leak #2064

@ag-agilent

Description

@ag-agilent

Hi,

I seem to be getting a memory leak when using the RangeSlider. First noticed it in VS2015 diagnostic tools, then checked with JetBrains dotMemory which confirmed a "Dependency Property Leak". This appears to be a result of calling AddValueChanged in the RangeSlider constructor and not having a matching RemoveValueChanged

DependencyPropertyDescriptor.FromProperty(ActualWidthProperty, typeof(RangeSlider)).AddValueChanged(this, delegate { ReCalculateSize(); });
            DependencyPropertyDescriptor.FromProperty(ActualHeightProperty, typeof(RangeSlider)).AddValueChanged(this, delegate { ReCalculateSize(); });

Described here: http://o.oz-code.com/top-3-memory-leak-inducing-pitfalls-of-wpf-programming

I rebuilt MahApps.Metro with the two AddValueChanged lines remove and confirmed the leak is no longer there. I don't know if it was the correct thing to do but my fix for replacing those lines was to override OnPropertyChanged:

        protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
        {
            base.OnPropertyChanged(e);
            if (e.Property == ActualWidthProperty || e.Property == ActualHeightProperty)
            {
                ReCalculateSize();
            }
        }

Thank you for the awesome library!
Regards,
Andrew

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions