C++ WebBrowser控件的内存释放

 接上文,内嵌了一个webbrowser,当窗口关闭后,内存会持续占用并不会释放。

C++释放WebBrowser控件内存代码:

HANDLE pHandle = GetCurrentProcess();
SetProcessWorkingSetSize(pHandle, -1, -1);

 

解决办法来源:http://social.msdn.microsoft.com/Forums/en-US/ieextensiondevelopment/thread/88c21427-e765-46e8-833d-6021ef79e0c8/

[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);

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注