I\'m having a strange memory leak using element host on windows forms. I have a main form, which opens another form, the one that only haves the elementhost control on it (which
if the link will break again, here is solution (copy-pasted)
Posted by KGy on 22.10.2010 at 6:12 A possible workaround: Put the following code into the Dispose or another release method of your control/form that contains the ElementHost control.
if (elementHost != null)
{
FrameworkElement fe = elementHost.Child as FrameworkElement;
if (fe != null)
{
// Memory leak workaround: elementHost.Child.SizeChanged -= elementHost.childFrameworkElement_SizeChanged;
SizeChangedEventHandler handler = (SizeChangedEventHandler)Delegate.CreateDelegate(typeof(SizeChangedEventHandler), elementHost, "childFrameworkElement_SizeChanged");
fe.SizeChanged -= handler;
}
elementHost.Child = null;
base.Dispose(disposing);
elementHost.Dispose();
elementHost.Parent = null;
elementHost = null;
}