I have a requirement to host WPF Control on Winform User control. To achieve this I used ElementHost control. When I run Ants Memory profiler , I got know that There is a Huge memory leak in the ElementHost control. Please find the attached retention graph as below and kindly help me to fix the Memoryleak .
I ran into exactly same memory leaking situation with exactly same symptoms. Here's how I handled the situation.
ElementHost class have PropertyMap property which is collection that maps WinForms control property to WPF control property.
In this particular case, memory is leaking through BackgroundImage that keeps MemoryStream instance. And so, the solution is to remove BackgroundImage property mapping:
elementHost.PropertyMap.Remove("BackgroundImage");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With