الخميس، 11 يونيو 2015

Flush Memory


        [DllImportAttribute("kernel32.dll", EntryPoint = "SetProcessWorkingSetSize",                  ExactSpelling = true,
         CharSet = CharSet.Ansi, SetLastError = true)]
        ////[return: MarshalAs(UnmanagedType.Bool)]
        private static extern int SetProcessWorkingSetSize(IntPtr process, int                          minimumWorkingSetSize,
             int maximumWorkingSetSize);
        /// <summary>
        /// Will request to flush the memory
        /// </summary>
        public static void FlushMemory()
        {
            GC.Collect(GC.MaxGeneration);
            GC.WaitForPendingFinalizers();

            //if (Environment.OSVersion.Platform == PlatformID.Win32NT)
            SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle, -1, -1);
        } 

ليست هناك تعليقات:

إرسال تعليق