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

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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
ITstalkerITstory