winform,WPF 释放内存垃圾,减少资源占用方法

 [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()即可..

http://xuxuhuy.blog.163.com/blog/static/1032932920116110204080/

原文地址:https://www.cnblogs.com/zhaogaojian/p/8477073.html