namespace myCommon
{
public class SysVar
{
[DllImport("kernel32.dll")]
public static extern bool SetProcessWorkingSetSize(IntPtr handle, int minimumWorkingSetSize, int maximumWorkingSetSize);
/// <summary>
/// 释放内存
/// </summary>
public static void FlushMemory()
{
GC.Collect();
GC.WaitForPendingFinalizers();
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
{
SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle, -1, -1);
}
}
}
}
//使用例子:
private void xfrmBase_FormClosed(object sender, FormClosedEventArgs e)
{
myCommon.SysVar.FlushMemory();
}
.net C# 释放内存 例子,布布扣,bubuko.com
原文:http://www.cnblogs.com/hclw/p/3898663.html