using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; namespace Zhaizj.Framework.Utils { /// /// 用于释放内存垃圾,即时释放 /// public class GCFlash { [DllImport("kernel32.dll")] public static extern bool SetProcessWorkingSetSize(IntPtr proc, int min, int max); public static void FlushMemory() { GC.Collect(); GC.WaitForPendingFinalizers(); if (Environment.OSVersion.Platform == PlatformID.Win32NT) { SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle, -1, -1); } } } }