using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace OTSIncAReportApp { public static class MemoryManagementClass { /// /// 回收内存 /// public static void FlushMemory() { //回收内存 MemoryManagement mm = new MemoryManagement(); mm.FlushMemory(); } [System.Runtime.InteropServices.DllImport("coredll.dll")] [return: System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.Bool)] public static extern bool DeleteObject(IntPtr hgdiobj); public class MemoryManagement { [System.Runtime.InteropServices.DllImport("kernel32.dll")] public static extern bool SetProcessWorkingSetSize(IntPtr proc, int min, int max); public void FlushMemory() { GC.Collect(); GC.WaitForPendingFinalizers(); if (Environment.OSVersion.Platform == PlatformID.Win32NT) { SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle, -1, -1); } } } } }