SetProcessWorkingSetSize减少内存占用
生活随笔
收集整理的這篇文章主要介紹了
SetProcessWorkingSetSize减少内存占用
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
系統啟動起來以后,內存占用越來越大,使用析構函數、GC.Collect什么的也不見效果,后來查了好久,找到了個辦法,就是使用 SetProcessWorkingSetSize函數。這個函數是Windows API 函數。下面是使用的方法:
[System.Runtime.InteropServices.DllImportAttribute("kernel32.dll",?EntryPoint?=?"SetProcessWorkingSetSize",?ExactSpelling?=?true,?CharSet?=System.Runtime.InteropServices.CharSet.Ansi,?SetLastError?=?true)]
private?static?extern?int?SetProcessWorkingSetSize(IntPtr?process,?int?minimumWorkingSetSize,?int?maximumWorkingSetSize);
public?void?Dispose()
{
????GC.Collect();
????GC.SuppressFinalize(this);
????if?(Environment.OSVersion.Platform?==?PlatformID.Win32NT)
????{
????????SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle,?-1,?-1);
????}
}
使用這個函數也會有些問題,具體的可以參見:
http://hi.baidu.com/taobaoshoping/blog/item/a1f6baf52d523a21bd3109f5.html
?
轉載于:https://www.cnblogs.com/pdfw/archive/2009/04/22/1441477.html
總結
以上是生活随笔為你收集整理的SetProcessWorkingSetSize减少内存占用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 精准客户数据服务
- 下一篇: 【译】XNA Shader 程序设计(二