I'm using this code from StackOverflow (How can I get HTML source code from TWebBrowser) to get the full response from a webpage:
function TMain.GetWebBrowserHTML(const WebBrowser: TWebBrowser): String;
var
LStream: TStringStream;
Stream: IStream;
LPersistStreamInit: IPersistStreamInit;
begin
if not Assigned(WebBrowser.Document) then
Exit;
LStream := TStringStream.Create('');
try
LPersistStreamInit := WebBrowser.Document as
IPersistStreamInit;
Stream := TStreamAdapter.Create(LStream, soReference);
LPersistStreamInit.Save(Stream, True);
Result := LStream.DataString;
finally
LStream.Free();
end;
end;
After a couple of hundred calls to the routine with some large web pages, I'm out of memory.
Apparently there is a known problem with the component's Document property, but the suggestion of replacing WebBrowser.Document with WebBrowser.DefaultInterface.Document doesn't help. I really don't want to try to fix the VCL, and the other suggestion of calling Release might work if I knew where and how to do it. And the leak could be something else entirely. This code is above my pay grade.
I can't use TIdHTTP because of some scripting that has to occur, and I need the visual anyway.
See also: TWebbrowser massive memory leaks : no solution so far