如何解决在.net WebBrowser控件内存泄漏? [英] How to get around the memory leak in the .NET Webbrowser control?

查看:891
本文介绍了如何解决在.net WebBrowser控件内存泄漏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是广为人知的,老问题与.NET WebBrowser控件。

This is a widely-known, old issue with the .NET Webbrowser control.

摘要:具有.NET WebBrowser控件导航到一个页面增加了永远不会被释放的内存使用

Summary: Having the .NET webbrowser control Navigate to a page increases memory usage that is never freed.

重现内存泄漏:添加一个WebBrowser控件到窗体。用它来导航到任何网页你想。约:空白作品,向下滚动在谷歌图像,直到您的使用情况为100MB +,然后浏览到其他地方几乎没有发现任何被释放的内存是一个更生动的实例

Reproduce the memory leak: Add a WebBrowser control to a form. Use it to Navigate to whatever pages you'd like. about:blank works, scrolling down on Google Images until your usage is 100MB+ and then browsing elsewhere to notice barely any of that memory is freed is a more dramatic demonstration.

我给一个应用程序当前要求包括运行它对于长时间,显示有限IE7浏览器窗口。不希望用钩子,BHO对象和组策略的一些混蛋设定运行IE7本身要么,尽管这看起来像回退在这个时候。 嵌入浏览器到Windows窗体应用程序。 使用不同的浏览器的基础,不是我一个可行的选择。 IE7是必需的。

My current requirements for an application include running it for long periods of time, displaying a limited IE7 browser window. Running IE7 itself with some bastard setup of hooks, BHOs and group policies isn't desired either, although that's looking like the fallback at this time. Embedding a browser into a Windows Forms application is. Using a different browser base is not an available option for me. IE7 is required.

previous线程以及与此已知的内存泄漏文章:

Previous threads and articles relating to this known memory leak:

  • <一个href="http://www.vbforums.com/showthread.php?t=644658">http://www.vbforums.com/showthread.php?t=644658
  • <一个href="http://stackoverflow.com/questions/904478/how-to-fix-the-memory-leak-in-ie-webbrowser-control">How修复在IE浏览器控件的内存泄漏?
  • <一个href="http://stackoverflow.com/questions/2069314/memory-leak-when-using-wpf-webbrowser-control-in-multiple-windows">Memory使用多个窗口WPF WebBrowser控件时,泄漏
  • <一个href="http://social.msdn.microsoft.com/Forums/en-US/ieextensiondevelopment/thread/88c21427-e765-46e8-833d-6021ef79e0c8/">http://social.msdn.microsoft.com/Forums/en-US/ieextensiondevelopment/thread/88c21427-e765-46e8-833d-6021ef79e0c8/
  • <一个href="http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/8a2efea4-5e75-4e3d-856f-b09a4e215ede">http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/8a2efea4-5e75-4e3d-856f-b09a4e215ede
  • <一个href="http://dotnetforum.net/topic/17400-appdomain-webbrowser-memory-leak/">http://dotnetforum.net/topic/17400-appdomain-webbrowser-memory-leak/
  • http://www.vbforums.com/showthread.php?t=644658
  • How to Fix the Memory Leak in IE WebBrowser Control?
  • Memory leak when using WPF WebBrowser control in multiple windows
  • http://social.msdn.microsoft.com/Forums/en-US/ieextensiondevelopment/thread/88c21427-e765-46e8-833d-6021ef79e0c8/
  • http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/8a2efea4-5e75-4e3d-856f-b09a4e215ede
  • http://dotnetforum.net/topic/17400-appdomain-webbrowser-memory-leak/

经常提出的修正不工作:

Often-proposed fixes that DO NOT WORK:

  • 将不同的页面没有关系。约:空白引发的泄漏。它不需要一个页面来了JavaScript,或者任何其他额外的技术。
  • 使用不同版本的Internet Explorer并不重要。 7,8,9都表现出相同的症状,而据我所知,所有的版本可以在控制相同的内存泄漏。
  • 的Dispose()荷兰国际集团控制的没有帮助。
  • 在垃圾收集于事无补。 (事实上​​,研究我做了这个指示泄漏发生在非托管COM code。该Webbrowswer控制套。)
  • 最小化和过程可用内存设置为-1,-1(SetProcessWorkingSetSize()或simimlar。)不仅降低物理内存使用情况,对虚拟内存没有任何影响。
  • 在调用WebBrowser.Stop()不是一个解决方案,以及使用什么,但静态网页,无不是仅仅略有减少漏气做更多的休息时间的功能。
  • 强制等待一个文档导航到另一个之前完全加载也于事无补。
  • 加载控制在一个单独的AppDomain没有解决的问题。 (我还没有这样做我自己,但研究表明,人有这个路线没有成功。)
  • 使用不同的包装,如csexwb2没有帮助,因为这也遭受了同样的问题。
  • 清除Internet临时文件缓存什么都不做。问题出在主动记忆,而不是在磁盘上。
  • Going to different pages does not matter. about:blank triggers the leak. It does not require a page to have javascript, or any other extra technology.
  • Using different versions of Internet Explorer does not matter. 7, 8, and 9 all exhibit the same symptoms, and as far as I've heard, all versions have the same memory leak in the control.
  • Dispose()ing of the control does not help.
  • Garbage Collecting does not help. (In fact, research I've done into this indicates the leak is in unmanaged COM code that the Webbrowswer control wraps.)
  • Minimizing and setting process available memory to -1, -1(SetProcessWorkingSetSize() or simimlar.) only reduces physical memory usage, has no impact on virtual memory.
  • Calling WebBrowser.Stop() is not a solution, and breaks functionality for using anything but static webpages, without doing more than just minimizing the leak slightly.
  • Forcing a wait for a document to load completely before Navigating to another also doesn't help.
  • Loading the control in a separate appDomain does not fix the issue. (I've not done this myself, but research shows others having no success with this route.)
  • Using a different wrapper such as csexwb2 does not help, as this also suffers from the same issue.
  • Clearing the Temporary Internet Files cache does nothing. The problem is in active memory, not on disk.

在整个应用程序被关闭并重新启动存储器被清除。

Memory is cleared when the entire application is closed and restarted.

我愿意写在直接COM或Windows API自己的浏览器控件,如果这是一个换确保修复的问题。当然,我会$​​ P $ PFER一个不太复杂的修复;我宁愿避免下降到较低的水平做的事情,因为我不希望重新发明轮子在支持的浏览器的功能方面。 Letalone复制的卷你自己风格的浏览器IE7功能和非标准的行为。

I'm willing to write my own browser control in COM or Windows API directly, if that's a for-sure fix to the problem. Of course, I would prefer a less complicated fix; I'd rather avoid going down to lower levels to do things, because I don't want to be reinventing the wheel in terms of supported features of a browser. Letalone duplicating IE7 features and nonstandard behaviours in a roll-your-own style browser.

帮助?

推荐答案

此泄漏似乎是在非托管内存泄漏,那么你在过程中什么也不做是要收回的内存。从你的文章中,我可以看到你已经尝试避免泄漏相当广泛,并没有成功。

This leak appears to be a leak in unmanaged memory, so nothing you do in your process is going to reclaim that memory. From your post I can see that you've tried avoid the leak quite extensively and without success.

我会建议不同的方法,如果可行的。创建使用Web浏览器控制一个单独的应用程序和应用程序启动。使用所描述的方法<一href="http://stackoverflow.com/questions/4608130/how-to-embed-window-from-another-application-in-our-wpf-window-as-user-control">here你自己现有的应用程序中嵌入新创建的应用程序。沟通与使用WCF或.NET远程该应用程序。从时间重新启动子进程,以时间来prevent从抽空多的内存。

I would suggest a different approach if feasible. Create a separate application that uses web browser control and start it from your application. Use the method described here to embed newly created application within your own existing application. Communicate with that application using WCF or .NET remoting. Restart the child process from time to time to prevent it from taking to much memory.

这当然是相当复杂的解决方案,并重新启动的过程很可能看起来很丑陋。你也许可能采取重启每次用户导航到另一个页面,整个浏览器应用程序。

This of course is quite complicated solution and the restart process could probably look ugly. You might maybe resort to restarting the whole browser application every time user navigates to another page.

这篇关于如何解决在.net WebBrowser控件内存泄漏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆