简体   繁体   English

IE WebBrowser控件中的内存泄漏

[英]Memory Leak in IE WebBrowser Control

In C# I use as a web-browser control ( Watin browser control ) where I run this control into another thread of the main thread. 在C#中,我用作Web浏览器控件(Watin浏览器控件),我将此控件运行到主线程的另一个线程中。

After a few hours, a memory leak is created. 几个小时后,会产生内存泄漏。

There is another post ( here : How to Fix the Memory Leak in IE WebBrowser Control? or How to get around the memory leak in the .NET Webbrowser control? ) that suggests to call " SetProcessWorkingSetSize " from KERNEL32.DLL . 还有另一篇文章(这里: 如何修复IE WebBrowser控件中的内存泄漏?如何解决.NET Webbrowser控件中的内存泄漏? ),建议从KERNEL32.DLL调用“ SetProcessWorkingSetSize ”。

The workaround is to minimize the winform of web-browser control. 解决方法是最小化Web浏览器控件的winform。

So my question is: if there is another way to solve this problem? 所以我的问题是:如果有另一种方法来解决这个问题? and if not, if I use an alternative web-browser control like mozilla-gecko I will solve this memory-leak. 如果没有,如果我使用像mozilla-gecko这样的替代网络浏览器控件,我将解决这个内存泄漏问题。

The solution is to call the garbage collector & force the Windows OS to clean the memory. 解决方案是调用垃圾收集器并强制Windows操作系统清理内存。 For example into finally you can write : 例如最后你可以写:

finally
{
    GC.Collect();
    GC.WaitForPendingFinalizers();

    EmptyWorkingSet(GetCurrentProcess());
}

EmptyWorkingSet forces the OS to clean the memory. EmptyWorkingSet强制操作系统清理内存。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM