Winform内存回收的一段代码

Timer控件10秒或者更多时间执行一次,觉得没有必要秒为单位吧。用DevExpress确实占用内存比较大。

using System.Runtime.InteropServices;
	#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


 

你可能感兴趣的:(Winform内存回收的一段代码)