프로그램/C#

C# 메모리 줄이기, 메모리 강제회수

알 수 없는 사용자 2013. 3. 8. 02:08



using System.Runtime.InteropServices; 

 
 

        #region 강제 메모리 회수 

        [DllImportAttribute("kernel32.dll", EntryPoint = "SetProcessWorkingSetSize", ExactSpelling = true, CharSet = 

CharSet.Ansi, SetLastError = true)] 

        private static extern int SetProcessWorkingSetSize(IntPtr process, int minimumWorkingSetSize, int 

maximumWorkingSetSize); 

        public static void FlushMemory() 
        { 

            GC.Collect(); 

            GC.WaitForPendingFinalizers(); 

            if (Environment.OSVersion.Platform == PlatformID.Win32NT) 
            { 

                SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle, -1, -1); 
            } 

        } 

        #endregion