user503386
user503386

Reputation: 1108

WindowInteropHelper.Handle — do I need to release it?

In WPF I'm getting IntPtr handle using this code:

IntPtr mainWindowHandle = new WindowInteropHelper(Application.Current.MainWindow).Handle

When I finish using this handle, do I need to release it in anyway (e.g. using Marshal.FreeHGlobal() method) ?

EDIT: I was thinking about Marshal.FreeHGlobal(), not Marshal.Release(), sorry!

Upvotes: 0

Views: 900

Answers (1)

Hans Passant
Hans Passant

Reputation: 941515

This is not in any way related to COM, Marshal.Release() does not apply. You simply get a copy of the native window handle, it does not have to be released. You need to stop using the handle when the window is destroyed. Signaled by the Window.Close event.

Upvotes: 4

Related Questions