프로그램/C# 2013. 3. 8. 02:08

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




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 



'프로그램 > C#' 카테고리의 다른 글

C# 폼 투명하게 하기  (0) 2013.03.12
C# 파일경로  (0) 2013.03.08
C# 웹 검색  (0) 2013.03.08
C# 키 이벤트 ...  (0) 2013.03.08
C# try - catch 예외 처리  (0) 2013.03.08