C#强制清除缓存

Posted x_蜡笔小新

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C#强制清除缓存相关的知识,希望对你有一定的参考价值。

#region 强制清除缓存
        [DllImport("kernel32.dll", EntryPoint = "SetProcessWorkingSetSize")]
        public static extern int SetProcessWorkingSetSize(IntPtr process, int minSize, int maxSize); ////// 释放内存 

        public static void ClearMemory()
        {
            GC.Collect();
            GC.WaitForPendingFinalizers();
            if (Environment.OSVersion.Platform == PlatformID.Win32NT)
            {
                SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle, -1, -1);
            }
        } 
        #endregion

  

以上是关于C#强制清除缓存的主要内容,如果未能解决你的问题,请参考以下文章