这段时间在用WebBrowser,发现只要不释放,这家伙占的内存,就会与越来越大。我都到过1G多,好吓人。于是百度查找解决方法最终在下面的网址中到到了,在此先表示感谢。
网站:http://bbs.csdn.net/topics/390164193
解决方法如下:
-- in class definition
[DllImport("KERNEL32.DLL", EntryPoint = "SetProcessWorkingSetSize", SetLastError = true, CallingConvention = CallingConvention.StdCall)]
internal static extern bool SetProcessWorkingSetSize(IntPtr pProcess, int dwMinimumWorkingSetSize, int dwMaximumWorkingSetSize);
[DllImport("KERNEL32.DLL", EntryPoint = "GetCurrentProcess", SetLastError = true, CallingConvention = CallingConvention.StdCall)]
internal static extern IntPtr GetCurrentProcess();
-- code to call when you want to reduce the memory
IntPtr pHandle = GetCurrentProcess();
SetProcessWorkingSetSize(pHandle, -1, -1);
本人在WIN7,VS2013下测试可行