在需要调用垃圾回收的地方调用ClearMemory()

public static void ClearMemory()
{
    GC.Collect();
    GC.WaitForPendingFinalizers();
    if (Environment.OSVersion.Platform == PlatformID.Win32NT)
    {
        SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, -1, -1);
    }
}

[DllImport("kernel32.dll")]
public static extern int SetProcessWorkingSetSize(IntPtr process, int minSize, int maxSize);

相关文章:

  • 2021-10-15
  • 2021-07-12
  • 2022-02-13
猜你喜欢
  • 2021-11-20
  • 2022-12-23
  • 2022-02-04
  • 2021-07-16
  • 2021-11-20
  • 2021-09-28
相关资源
相似解决方案