C# Winform应用程序占用内存较大解决方法
1.SetProcessWorkingSetSize减少内存占用;
2.GC.Collect();回收内存
C# Winform应用程序占用内存较大解决方法代码如下:
[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)
{
Menu.SetProcessWorkingSetSize( System.Diagnostics.Process.GetCurrentProcess().Handle, -1, -1 );
}
}
原文链接:http://www.jxszl.com/biancheng/C/556421.html