Web浏览器问题C# [英] Webbrowser Problem C#

查看:120
本文介绍了Web浏览器问题C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经用C#制作了一个WebBrowser.我在一个接一个的系列中打开了几个站点.

我也有一个处置按钮.

当我单击WebBrowser时,它就被丢弃了.简单的.我的问题:当我单击处置"按钮时,为什么不释放Web浏览器的内存资源?

就像这样:我的编程序从5000K逐渐增加到现在的40000k,当我单击处置"按钮时,它应该释放Web浏览器正在使用的资源,为什么它不这样做?

我什至调用了GC.collect,但效果不好.第一个版本也处理非托管资源.


如果存在对对象的引用,则调用Dispose GC.Collect 将无济于事.因为那样会阻止GC释放内存.尝试确保不是这种情况.


---------
(回应评论)

是的,但是我指的是某些参考可能仍保留在内存中的可能性.例如,如果您有一个静态成员持有对该对象的引用,而该对象具有对该控件的成员引用,则GC将无法声明该内存.这是托管的等效于内存泄漏.


Web控件中存在已知的内存泄漏.
实例化Webbrowser实例后,"Dispose"方法和"GC"将无济于事.

请参阅ms的kb文章:
http://support.microsoft.com/kb/893629 [ http://social.msdn.microsoft.com/Forums/zh/ieextensiondevelopment/thread/88c21427-e765-46e8-833d-6021ef79e0c8 [ http://social.msdn中的可信"变通方法.microsoft.com/Forums/en/ieextensiondevelopment/thread/88c21427-e765-46e8-833d-6021ef79e0c8 [ 解决方案

Did you cal WebBrowser.Dispose(true), or just WebBrowser.Dispose()? The first version disposes unmanaged resources as well.


Calling Dispose or GC.Collect won''t help if there are references holding on to the object. Because that will prevent the GC from freeing up the memory. Try and make sure that that is not the case.

[Edit]
---------
(in response to the comment)

Yeah but what I was referring to was the possibility of some references still remaining in memory. Example if you have a static member holding a reference to an object that has a member reference to this control, then the GC won''t be able to claim the memory. It''s the managed equivalent of a memory leak.


There is a known memory leak in the webcontrol.
The ''Dispose'' method and the ''GC'' won''t help you, once you instantiated a Webbrowser instance.

See this kb article from ms:
http://support.microsoft.com/kb/893629[^]
and on msdn social forum:
http://social.msdn.microsoft.com/Forums/en/ieextensiondevelopment/thread/88c21427-e765-46e8-833d-6021ef79e0c8[^]

Also, search on google for "webcontrol memoryleak". Years and years have passed and there is no fix for it for .NET. Even the "believed" workarounds in http://social.msdn.microsoft.com/Forums/en/ieextensiondevelopment/thread/88c21427-e765-46e8-833d-6021ef79e0c8[^] don''t work.

Alternative is to use Geckofx or WebKit.
I like WebKit, it releases it''s allocated memory after you call dispose or when you navigate to another webpage.


这篇关于Web浏览器问题C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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