winform,WPF 释放内存垃圾,减少资源占用方法
摘自:http://xuxuhuy.blog.163.com/blog/static/1032932920116110204080/
[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); } } 用法:只需要在你希望释放的时候调用FlushMemory()即可..