I'm trying to figure out whether the following situation produces a memory leak or not.
I am getting a window handle from a WebBrowser control (there is a reason for this)
IntPtr p = webBrowser1.FindForm().Handle;
Later, I am releasing that handle in an overridden dispose method
protected override void Dispose(bool disposing)
{
hwnd = IntPtr.Zero;
base.Dispose(disposing);
}
Is there something evil behind my Dispose
method that might cause a memory leak?
This might be pretty obvious to some, but I am hunting memory leaks so I'm trying to verify every line of code.
There is no significance in setting your HWND to IntPtr.Zero.
IntPtr is a value type, so having the value in that variable has no effect on anything. It does not keep any object alive. It's just a number that you are setting to 0.
If you got the HWND from an existing window, then no handle should have been duplicated and you don't have to release it. The HWND will be destroy when the form is closed.
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