C#释放内存的方法
标签:public poi env current max pen getc long 占用
原文:https://blog.csdn.net/zsy619/article/details/79181719
---------------------
如何释放内存:
[DllImport("kernel32.dll", EntryPoint = "SetProcessWorkingSetSize")]
public static extern int SetProcessWorkingSetSize(IntPtr process, int minSize, int maxSize);
///
/// 释放内存
///
public static void ClearMemory()
{
GC.Collect();
GC.WaitForPendingFinalizers();
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
{
SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, -1, -1);
}
}
如何获取当前应用占用的内存大小:
///
/// 释放内存
///
public static void ClearMemory()
{
//获得当前工作进程
Process proc = Process.GetCurrentProcess();
long usedMemory = proc.PrivateMemorySize64;
if (usedMemory > 1024 * 1024 * 20)
{
GC.Collect();
GC.WaitForPendingFinalizers();
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
{
SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, -1, -1);
}
}
}
C#释放内存的方法
标签:public poi env current max pen getc long 占用
原文地址:https://www.cnblogs.com/dabexiong/p/9907648.html
文章来自:
搜素材网的
编程语言模块,转载请注明文章出处。
文章标题:
C#释放内存的方法
文章链接:http://soscw.com/index.php/essay/101039.html
评论