TWebbrowser大量内存泄漏:迄今为止尚无解决方案 [英] TWebbrowser massive memory leaks : no solution so far
问题描述
我有一个使用 TWebbrowser
的应用程序来定期导航到特定的URL并提取一些数据.该应用程序保持24x7全天候运行,并在页面中进行大量导航.
问题是 TWebbrowser
有一个众所周知的内存泄漏问题,其中,每次导航到新页面时,用于该应用程序的内存都会增加.一段时间后,我的应用程序可以轻松使用超过2GB的RAM.在导航数百次后,将抛出内存不足"
或系统资源不足"
异常,并且解决该问题的唯一方法是重新启动应用程序./p>
奇怪的是, FASTMM
从不显示这些泄漏.当我使用我的应用程序几分钟并关闭它时,没有任何报告.
多年来,我一直在寻找解决这个问题的方法(实际上是从2007年编写应用程序的第一个版本以来).有一些解决方法,但实际上,它们都不能解决问题.对我来说,唯一的解决方法是定期关闭和打开该应用程序.
我已经测试了 SetProcessWorkingSetSize
方法,但是它只是暂时缩小了应用程序使用的内存.几秒钟后,该应用程序再次使用大量内存.
我也尝试过 EmbeddedWB
,但是由于它是从 TWebbrowser
衍生而来的,因此也遇到了同样的问题.
顺便说一句,我不能使用像 IdHTTP
这样的简单组件,因为我需要在访问的网站中进行一些JavaScript操作.
有人知道这个问题真的有解决方案吗?
请参阅此处),也可以避免出现有问题的属性(例如,使用 browser.DefaultInterface.Document
browser.Document
).
I have an application that uses TWebbrowser
to periodically navigate to a specific URL and extract some data. The app keeps runing 24x7 and does a lot of navigation in pages.
The problem is that TWebbrowser
has a well-known memory leak problem, in which every time you navigate to a new page, the memory used for the application is increased. My app can easily use more than 2GB of RAM after some time. And after navigating hundred of times an 'Out of memory'
or 'Out of system resources'
exception is thrown and the only way to work around it is restarting the application.
The strange thing is FASTMM
never shows these leaks. When I use my app for some minutes and close it, nothing is reported.
I've been searching for a solution for this problem for years (in fact since 2007 when I wrote the first version of my application). There are some workarounds but in fact, none of them solves the problem. For me the only workaround is really to close and open the app periodically.
I already tested the SetProcessWorkingSetSize
approach, but it only shrinks the memory used by the app temporarily. After some seconds, the app uses a huge amount of memory again.
I also tried EmbeddedWB
, but as it descends from TWebbrowser
, it's plagued by the same issue.
By the way, I can't use a simple component like IdHTTP
, because I need to do some JavaScript manipulation in the website visited.
Does anyone know if is there REALLY a solution for this problem?
QC#106829 describes one possible cause of memory leaks with TWebBrowser. Accessing Document
(and any other properties that are implemented via TOleControl.GetIDispatchProp
or TOleControl.GetIUnknownProp
) causes leaks because it calls AddRef without ever calling Release. As a workaround, you can manually call Release, or you can patch the VCL (see here), or you can avoid the problematic properties (for example, by using browser.DefaultInterface.Document
instead of browser.Document
).
这篇关于TWebbrowser大量内存泄漏:迄今为止尚无解决方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!