让.NET程序快速释放内存的办法
文章录入:王子 责任编辑:dingkai1983 147 【字体:小 大】 让.NET程序快速释放内存的办法 [DllImport("kernel32.dll")] public static extern bool SetProcessWorkingSetSize(IntPtr process, int minSize, int maxSize); public static void GarbageCollect()
{ GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); } public static void FlushMemory()
{ GarbageCollect(); if (Environment.OSVersion.Platform == PlatformID.Win32NT)
{ Win32.SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle, -1, -1); } } NET里面还有一个类可以达到这个效果
System.Diagnostics.Process.GetCurrentProcess().MinWorkingSet = new System.IntPtr(5); 采用定时释放+窗体打开的时候,效果很好,估计程序占的内存会在20以下
摘自红色黑客联盟(www.) 原文:http://www./kf/201008/55126.html
|
|