improve memory usage

Signed-off-by: Shawn Yuan (from Dev Box) <shuaiyuan@microsoft.com>
This commit is contained in:
Shawn Yuan (from Dev Box)
2025-12-05 08:48:48 +08:00
parent 8f6bd72679
commit eb69549320

View File

@@ -121,6 +121,12 @@ public sealed partial class MainWindow : WindowEx, IDisposable
_isVisible = false; _isVisible = false;
RemoveGlobalMouseHook(); RemoveGlobalMouseHook();
// Reduce memory usage when hidden
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle, -1, -1);
} }
internal void RequestHide() internal void RequestHide()
@@ -677,6 +683,9 @@ public sealed partial class MainWindow : WindowEx, IDisposable
[DllImport("user32.dll")] [DllImport("user32.dll")]
private static extern bool GetCursorPos(out NativePoint lpPoint); private static extern bool GetCursorPos(out NativePoint lpPoint);
[DllImport("kernel32.dll")]
private static extern bool SetProcessWorkingSetSize(IntPtr hProcess, int dwMinimumWorkingSetSize, int dwMaximumWorkingSetSize);
private const int WmXbuttondown = 0x020B; private const int WmXbuttondown = 0x020B;
private delegate IntPtr LowLevelMouseProc(int nCode, IntPtr wParam, IntPtr lParam); private delegate IntPtr LowLevelMouseProc(int nCode, IntPtr wParam, IntPtr lParam);