1.把对象赋值为null

2.立即调用GC.Collect();
 
注意:这个也只是强制垃圾回收器去回收,但具体什么时候执行不确定。 
 
代码:
 
 
[System.Runtime.InteropServices.DllImportAttribute("kernel32.dll", EntryPoint = "SetProcessWorkingSetSize", ExactSpelling = true, CharSet =System.Runtime.InteropServices.CharSet.Ansi, SetLastError = true)]
        private static extern int SetProcessWorkingSetSize(IntPtr process, int minimumWorkingSetSize, int maximumWorkingSetSize);

 #region 内存回收
   public  void ClearMemory()
 {
     GC.Collect();
     GC.SuppressFinalize(this);
 
 
     if (Environment.OSVersion.Platform == PlatformID.Win32NT)
     {
         SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle, -1, -1);
     }
 }
 #endregion

ClearMemory();

 

 

https://blog.csdn.net/xwnxwn/article/details/78009071

相关文章:

  • 2021-06-02
  • 2022-12-23
  • 2022-12-23
  • 2021-06-22
  • 2022-12-23
  • 2021-12-13
  • 2021-12-10
猜你喜欢
  • 2021-12-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-24
  • 2021-09-14
  • 2021-12-13
相关资源
相似解决方案