With Twebbrower constantly open multiple Web pages, some versions of the operating system running for some time, found to occupy system memory up to hundreds of M, until the program is closed, the memory used to release.
This problem in the network has a lot of discussion, the more people's proposal is to use SetProcessWorkingSetSize (GetCurrentProcess (), -1,-1) to deal with, this flexible approach seems feasible.
Then there is a workaround in http://www.winu.cn/space-14160-do-blog-id-270.html, which mentions a memory leak in OLE and resolves the problem by overriding the OLE function.
Abandoned zhongs finally found the problem, without verification, plagiarism as follows:
Change Twebbrowser= Class (Tolecontrol) to twebbrowser= class (Trsolecontrol)
Unit rsolectrls;
Interface
Uses
Olectrls;
Type
Trsolecontrol = Class (Tolecontrol)
Protected
function Getidispatchprop (Index:integer): IDispatch;
function Getiunknownprop (Index:integer): IUnknown;
End
Implementation
{Tolecontrolfix}
function Trsolecontrol.getidispatchprop (Index:integer): IDispatch;
Var
Temp:tvardata;
Begin
GetProperty (Index, Temp);
Result: = IDispatch (Temp.vdispatch); Change to:
Pointer (Result): = Temp.vdispatch; This avoids the extra AddRef
End
function Trsolecontrol.getiunknownprop (Index:integer): IUnknown;
Var
Temp:tvardata;
Begin
GetProperty (Index, Temp);
Result: = IDispatch (Temp.vunknown); Change to:
Pointer (Result): = Temp.vunknown; This avoids the extra AddRef
End
End.
Another way to modify the source file is as follows:
Zhongs recommends adding an intermediate class to fix this problem in the middle of the inheritance relationship between Twebbrowser and Tolecontrol ...
But as I observed, I think Tolecontrol's flaws will spread to other existing and future automation controls, so my recommendation is to make the following modifications to Olectrls.pas:
function Tolecontrol.getidispatchprop (Index:integer): IDispatch;
Var
Temp:tvardata;
Begin
GetProperty (Index, Temp);
Result: = IDispatch (Temp.vdispatch);
Pointer (Result): = Temp.vdispatch;
End
function Tolecontrol.getiunknownprop (Index:integer): IUnknown;
Var
Temp:tvardata;
Begin
GetProperty (Index, Temp);
Result: = IUnknown (Temp.vunknown);
Pointer (Result): = Temp.vunknown;
End
And remember to recompile Olectrls.pas
RELATED links:
Http://blog.csdn.net/ScriptBaby/archive/2007/05/20/1618486.aspx
http://blog.csdn.net/ScriptBaby/article/details/1618486 http://blog.csdn.net/nhconch/article/details/7336192
Solutions for memory leak problems when using twebbrowser (use SetProcessWorkingSetSize function, or modify Olectrls.pas source to solve problems)