WebBrowser控件 - 高内存使用 [英] WebBrowser control - High memory use

查看:95
本文介绍了WebBrowser控件 - 高内存使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。我有一个Winform应用程序,其中包含一个web浏览器控件

,它可以永久地从一个页面导航到另一个页面,以进行一些

测试。我遇到的问题是,过了一段时间,应用程序是在内存中使用超过100或150 Mb的
,如果我让它继续,它可以离开

没有内存的系统。我在一些页面上一直在观看其他

的人在长时间导航

时遇到与此控制相同的问题,但我已经看不到任何关于它的答案...


这里有人有这个控件的行为的答案吗?我已经尝试了

一切都减少了应用程序中的内存使用但随着webbrowser

导航越来越多,应用程序的内存使用保持

增加...


提前致谢。


问候。


Cesar。

Hello people. I''m having a Winform app that contains a webbrowser control
that keeps navigating from one page to another permanentrly to make some
tests. The problem I''m having is that after a while, the application is
using more than 100 or 150 Mb in RAM, and if I let it continue, it can leave
the system without memory. I''ve been watching in some pages that other
people has the same problem with this control when keep navigating for a
long period of time, but I''ve seen no answers at all about it...

Does anyone here has an answer for this control''s behaviour?? I''ve tried
everything to reduce the memory use in the application but as the webbrowser
navigates more and more, the memory use of the application keeps
increasing...

Thanks in advance.

Regards.

Cesar.

推荐答案



这个问题是什么?


Cor

" Cesar" < cesardemi @ yahoo。 com。 arschreef in bericht

news:eQ ************** @ TK2MSFTNGP03.phx.gbl ...

And the problem with that is?

Cor
"Cesar" <cesardemi @ yahoo . com . arschreef in bericht
news:eQ**************@TK2MSFTNGP03.phx.gbl...

你好。我有一个Winform应用程序,其中包含一个web浏览器控件

,它可以永久地从一个页面导航到另一个页面,以进行一些

测试。我遇到的问题是,过了一段时间,应用程序是在内存中使用超过100或150 Mb的
,如果我让它继续,它可以

离开

系统没有内存。我在一些页面上一直在观看其他

的人在长时间导航

时遇到与此控制相同的问题,但我已经看不到任何关于它的答案...


这里有人有这个控件的行为的答案吗?我已经尝试了

一切都减少了应用程序中的内存使用但是随着

webbrowser

导航越来越多,内存使用应用程序保持

增加...


提前致谢。


问候。


Cesar。
Hello people. I''m having a Winform app that contains a webbrowser control
that keeps navigating from one page to another permanentrly to make some
tests. The problem I''m having is that after a while, the application is
using more than 100 or 150 Mb in RAM, and if I let it continue, it can
leave
the system without memory. I''ve been watching in some pages that other
people has the same problem with this control when keep navigating for a
long period of time, but I''ve seen no answers at all about it...

Does anyone here has an answer for this control''s behaviour?? I''ve tried
everything to reduce the memory use in the application but as the
webbrowser
navigates more and more, the memory use of the application keeps
increasing...

Thanks in advance.

Regards.

Cesar.


5月14日上午7:45,Cesar < cesardemi @ yahoo。 com。 arwrote:
On May 14, 7:45 am, "Cesar" <cesardemi @ yahoo . com . arwrote:

你好。我有一个Winform应用程序,其中包含一个web浏览器控件

,它可以永久地从一个页面导航到另一个页面,以进行一些

测试。我遇到的问题是,过了一段时间,应用程序是在内存中使用超过100或150 Mb的
,如果我让它继续,它可以离开

没有内存的系统。我在一些页面上一直在观看其他

的人在长时间导航

时遇到与此控制相同的问题,但我已经看不到任何关于它的答案...


这里有人有这个控件的行为的答案吗?我已经尝试了

一切都减少了应用程序中的内存使用但随着webbrowser

导航越来越多,应用程序的内存使用保持

增加...


提前致谢。


问候。


塞萨尔。
Hello people. I''m having a Winform app that contains a webbrowser control
that keeps navigating from one page to another permanentrly to make some
tests. The problem I''m having is that after a while, the application is
using more than 100 or 150 Mb in RAM, and if I let it continue, it can leave
the system without memory. I''ve been watching in some pages that other
people has the same problem with this control when keep navigating for a
long period of time, but I''ve seen no answers at all about it...

Does anyone here has an answer for this control''s behaviour?? I''ve tried
everything to reduce the memory use in the application but as the webbrowser
navigates more and more, the memory use of the application keeps
increasing...

Thanks in advance.

Regards.

Cesar.



Cesar,

我注意到Webbrowser使用大量内存如果webbrowser

有一个重闪的内容。请尝试浏览一些

不包含任何Flash内容的网站,然后比较结果。


谢谢,

OnurGüzel

Cesar,
I''ve noticed that Webbrowser uses high amount of memory if webbrowser
has a heavy flash content. Please try to navigate some sites which
doesn''t contain any flash content, then compare the results.

Thanks,

Onur Güzel




webbrowser控件是一个内存饥渴的控件,我已经尝试了

Mozilla控制但是当时它确实对

内存的要求不高但是它非常不稳定我不知道现在这是怎么回事

..


我曾经明白Mozilla和MS正在计划一个轻量级的

控件来显示html页面,但我不知道它的状态是什么? >
这些项目

解决方法可能是偶尔设置项目的工作设置

,而不是像最小化和

手动最大化应用程序(尝试并观察内存使用情况)


只要应用程序域加载内存将被保留

进行进一步处理

如果你的补偿资源不足,应用程序不需要内存

此刻(因为它是空闲的,内存将被退回并且

需要回收)

使用Windows窗体应用程序你可以看到这种行为(或者你

真的以为干净的形式需要大约+ -25 megs in .Net? )

有一种方法可以绕过这种行为,但是它带有一个小的价值,,,,

i写了一个远程项目并让我的客户抱怨内存消耗,所以我更深入地挖掘了这个

解决方案

我的项目(是一个单身人士)启动一个计时器,定期检查一个

日期时间变量,看看上次调用后如何经过曼尼时间

如果这个intervall是> = 1分钟它将调用SetProcessWorkingSetSize()

将数据使用量减少到最小值见下面的代码(对不起VB.Net

- ))

私有M_dtLastUsage作为DateTime

私有oCallback作为新TimerCallback(AddressOf OnTick)

私有oTimer作为Threading.Timer

Public Sub OnTick(ByVal stateInfo作为对象)

Dim DtCurrent As DateTime = Date.Now

Dim elapsed_time As TimeSpan

elapsed_time = DtCurrent.Subtract( M_dtLastUsage)

如果elapsed_time.TotalMinutes> = 1那么

oTimer.Dispose():oTimer = Nothing

SetProcessWorkingSetSize()

结束如果

结束次级

公共子新()

M_dtLastUsage = Date.Now

如果IsNothing(oTimer)那么

oTimer = New System.Threading.Timer(oCallback,Nothing,

System.TimeSpan.FromMinutes(0),System.TimeSpan.FromMinutes (1))

结束如果

结束子

私有声明自动功能SetProcessWorkingSetSize Lib" kernel32.dll"

(ByVal procHandle As IntPtr,ByVal min As Int32,ByVal max As Int32)As

Boolean

Friend Sub SetProcessWorkingSetSize()

试试

Dim Mem As Process = Process.GetCurrentProcess()

SetProcessWorkingSetSize(Mem.Handle,-1,-1)

Catch ex As Exception

结束尝试

结束子

这种方法的缺点是框架需要回收

内存再次这样理论上你的编程应该慢几毫秒,因为它可以是b $ b。

所以它更具有宇宙意义真的有一个目的,因为前卫

实际上是与最小化的应用程序相同的交换(物理和

虚拟内存的东西)


HTH


Michel Posseth

" Cesar" < cesardemi @ yahoo。 com。 arschreef in bericht

news:eQ ************** @ TK2MSFTNGP03.phx.gbl ...

The webbrowser control is a memory hungry control , i have ponce tryed the
Mozilla control instead but at that time it was indeed less demanding on
memory but it was verry unstable i do not know how this is now at this time
..

I had once understood that Mozilla and MS were planning a lightweight
control for showing html pages but i do not know what the status is for
these projects
A workaround could be to set the process working setsize of your project
once in a while ,than you get the same behaviour as minimizing and
maximizing the application by hand ( try it out and watch the memory usage )

as long as the application domain is loaded the memory will be reserved
for further processing
if your comp would run low on resources and the app does not need the memory
at the moment ( cause it is idle ,,, the memory would be given back and
needs to be reclaimed )
with a windows form application you can see this behavior to ( or did you
really thought a clean form needs about +- 25 megs in .Net ? )
there is a way you can bypass this behavior however it comes with a small
price ,,,,
i wrote once a remoting project , and had my customer complaining about the
memory consumption , so i digged a litle bit deeper and came with this
solution
my project ( wich is a singleton ) starts a timer that periodicly checks a
datetime var to see how manny time has passed after it was last called
if this intervall is >= 1 minute it will call SetProcessWorkingSetSize()
wich will trim the data usage to a minimum see below code ( sorry VB.Net
-) )
Private M_dtLastUsage As DateTime
Private oCallback As New TimerCallback(AddressOf OnTick)
Private oTimer As Threading.Timer
Public Sub OnTick(ByVal stateInfo As Object)
Dim DtCurrent As DateTime = Date.Now
Dim elapsed_time As TimeSpan
elapsed_time = DtCurrent.Subtract(M_dtLastUsage)
If elapsed_time.TotalMinutes >= 1 Then
oTimer.Dispose() : oTimer = Nothing
SetProcessWorkingSetSize()
End If
End Sub
Public Sub New()
M_dtLastUsage = Date.Now
If IsNothing(oTimer) Then
oTimer = New System.Threading.Timer(oCallback, Nothing,
System.TimeSpan.FromMinutes(0), System.TimeSpan.FromMinutes(1))
End If
End Sub
Private Declare Auto Function SetProcessWorkingSetSize Lib "kernel32.dll"
(ByVal procHandle As IntPtr, ByVal min As Int32, ByVal max As Int32) As
Boolean
Friend Sub SetProcessWorkingSetSize()
Try
Dim Mem As Process = Process.GetCurrentProcess()
SetProcessWorkingSetSize(Mem.Handle, -1, -1)
Catch ex As Exception
End Try
End Sub
The drawback of this method is that the framework needs to reclaim the
memory again so in theory your prog should be a few miliseconds slower as it
could be.
So it is more cosmetical as that it does really have a purpose as the prog
is actually gone to the swap same as a minimized application ( physical and
virtual memory thingy )

HTH

Michel Posseth
"Cesar" <cesardemi @ yahoo . com . arschreef in bericht
news:eQ**************@TK2MSFTNGP03.phx.gbl...

你好。我有一个Winform应用程序,其中包含一个web浏览器控件

,它可以永久地从一个页面导航到另一个页面,以进行一些

测试。我遇到的问题是,过了一段时间,应用程序是在内存中使用超过100或150 Mb的
,如果我让它继续,它可以

离开

系统没有内存。我在一些页面上一直在观看其他

的人在长时间导航

时遇到与此控制相同的问题,但我已经看不到任何关于它的答案...


这里有人有这个控件的行为的答案吗?我已经尝试了

一切都减少了应用程序中的内存使用但是随着

webbrowser

导航越来越多,内存使用应用程序保持

增加...


提前致谢。


问候。


Cesar。
Hello people. I''m having a Winform app that contains a webbrowser control
that keeps navigating from one page to another permanentrly to make some
tests. The problem I''m having is that after a while, the application is
using more than 100 or 150 Mb in RAM, and if I let it continue, it can
leave
the system without memory. I''ve been watching in some pages that other
people has the same problem with this control when keep navigating for a
long period of time, but I''ve seen no answers at all about it...

Does anyone here has an answer for this control''s behaviour?? I''ve tried
everything to reduce the memory use in the application but as the
webbrowser
navigates more and more, the memory use of the application keeps
increasing...

Thanks in advance.

Regards.

Cesar.



这篇关于WebBrowser控件 - 高内存使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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