본문 바로가기

IT/Dot Net

강제 메모리 회수

[code C#]
using System.Runtime.InteropServices;
[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);
 }
}
[/code]

출처 : http://takeone.pe.kr/category/General%20Dev./C%23%20Application
원본 : http://www.gosu.net/GosuWeb/ArticleMSView.aspx?ArticleCode=342