C# 内存回收
開發(fā)完成之后發(fā)現(xiàn)自己寫的程序內(nèi)存占用太高,找到如下解決方案
使用了一個(gè)timer每2s調(diào)用一次ClearMemory()
?
#region 內(nèi)存回收[DllImport("kernel32.dll", EntryPoint = "SetProcessWorkingSetSize")]public static extern int SetProcessWorkingSetSize(IntPtr process, int minSize, int maxSize);/// <summary>/// 釋放內(nèi)存/// </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
?
轉(zhuǎn)載于:https://www.cnblogs.com/huanjun/p/10832099.html
總結(jié)
                            
                        - 上一篇: Vue.js 源码目录设计(二)
 - 下一篇: 求善开头的成语接龙!