C# 内存回收
開發完成之后發現自己寫的程序內存占用太高,找到如下解決方案
使用了一個timer每2s調用一次ClearMemory()
?
#region 內存回收[DllImport("kernel32.dll", EntryPoint = "SetProcessWorkingSetSize")]public static extern int SetProcessWorkingSetSize(IntPtr process, int minSize, int maxSize);/// <summary>/// 釋放內存/// </summary>public static void ClearMemory(){GC.Collect();GC.WaitForPendingFinalizers();if (Environment.OSVersion.Platform == PlatformID.Win32NT){SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle, -1, -1);}}private void timer2_Tick(object sender, EventArgs e){ClearMemory();}#endregion
?
轉載于:https://www.cnblogs.com/huanjun/p/10832099.html
總結
- 上一篇: Vue.js 源码目录设计(二)
- 下一篇: Go语言调度器之调度main gorou