Alex Rivera | Logout

WPF element host memory leak

Asked 2011-06-16T14:50:47.213
9

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, at this point, does not have a wpf control child). Only 1 host form can be opened. Every time I open the form, the application memory raises by 20Mb, which are not free when the form is closes, so, after opening the host form several times, I run out of memory!. Now, if I remove the element host from the form, the memory remains stable.

I have been running CLRProfiler and ANTS, but I have found that all the problem resides on the element host, and I haven't found any workaround for this.

The wpfHost is used out-of-the-box, just dragged from the toolbar to the winForm.

Any idea how can I solve this?

Edit
Report

1 Answer

-1

I have a WPF ElementHost Object on my form and noticed a memory leak as well. What I was doing was something like this:

VAR cnt=this.MyHostControl.Child as MyWPFControl.WPObject;

and would do this in scope IE:

Private void Myfunction()
{

   VAR cnt=this.MyHostControl.Child as MyWPFControl.WPObject;
   cnt.Myproerty="Issue";

}

Not being a big fan of a VAR (Reminds of old COM days), I decided to create a global object like this:

MyWPFControl.WPObject cnt = null;

Then on the FormLoad_EvenT()

I initialized the object cnt like so:

cnt = this.MyHostControl.Child as MyWPFControl.WPObject;

Now my reference looks like this:

Private void Myfunction()
{

   cnt=this.MyHostControl.Child as MyWPFControl.WPObject;
   cnt.Myproerty="Issue";

}

And I do not need to create a var object.

Still testing and it looks like it maybe working. We will see over time.

answered 2011-10-06T14:56:48.937

Your Answer