C#内存回收
#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); } } #endregion
using System.Runtime.InteropServices; //可以用DllImport了
在你认为合适的地方调用ClearMemory()即可。
为API生,为框架死,为debug奋斗一辈子;吃符号亏,上大小写的当,最后死在需求上。