Vishal Banwari Vishal Banwari - 9 days ago 5
C# Question

How do I prevent memory leak from SolidColorBrush object?

There's no option to dispose SolidColorBrush.

How do I prevent memory leak from SolidColorBrush object?

I can't even use 'using' as SolidColorBrush doesn't implement IDisposable Interface.

Answer

Don't create new SolidColorBrush instances.

Use the predefined brushes in System.Windows.Media.Brushes.

Otherwise, create a single instance, and re-use that.