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# 释放内存 例子
时间: 2024-10-23 09:05:33