Reputation: 11973
right now I am acquiring the window and System Menu's handle by doing
IntPtr hwnd = new WindowInteropHelper(this).Handle;
IntPtr menuHandle = GetSystemMenu(hwnd, false);
WindowInteropHelper
is built in and GetSystemMenu
is Win 32 API
[DllImport("user32.dll")]
static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);
My question is, do I need to release either of the handles? If I do, how and when should I do that?
Upvotes: 1
Views: 276
Reputation:
It is a reference to a managed window, so the memory gets released when the window is closed. You don't need to free the pointer.
Look also at this answer: WindowInteropHelper.Handle — do I need to release it?
Similarly, also the following instruction is getting a copy/pointer of the menu already created and managed within the window lifecycle.
Upvotes: 1