C#即时释放内存
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
[DllImport("kernel32.dll")]
private static extern bool SetProcessWorkingSetSize(IntPtr process, int minSize, int maxSize);
/// <summary>
/// 即时释放内存
/// </summary>
public static void FlushMemory()
{
GC.Collect();
GC.WaitForPendingFinalizers();
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, -1, -1);
}
posted on 2017-06-13 16:31 qq1151219115 阅读(213) 评论(0) 编辑 收藏 举报