Delphi TWebBrowser Memory Leak

My application uses TWebBrowser, which loads a web page. The problem is that after closing the form containing TWebBrowser, the used memory is not freed. If I open and close the form, the memory just continues to grow.

Highlight the message about calling SetProcessWorkingSetSize () or CoFreeUnusedLibrariesEx () to solve this problem, but I'm not sure if any of them is the right solution.

Any idea to free the memory used by TWebBrowser?

+2
source share
7 answers

Q# 106829 TWebBrowser. Document ( , TOleControl.GetIDispatchProp TOleControl.GetIUnknownProp), , AddRef Release. Release, VCL (. ), (, browser.DefaultInterface.Document browser.Document).

+3

TWebBrowser , , Internet Explorer. , , , . , , Navigate('about:blank');. Navigate('about:blank'); OnClose OnCloseQuery. , .

+1

STOP TWebbrowser.

CEF4Delphi - , Chrome Internet Explorer. :

https://github.com/salvadordf/CEF4Delphi

0
Uses Winapi.PsAPI;
 ...
{$IFDEF WIN32}
procedure TForm1.MemoryFree;
var
  HandleCaptureProcessus: THandle;
  UnProcessus: TProcessEntry32;
  PIDProcessus: THandle;
  HandleProcessus: THandle;
  NameOfProcess: string;
begin
  PIDProcessus := 4294967295;
  NameOfProcess := ExtractFileName(Application.ExeName);

  HandleCaptureProcessus := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  UnProcessus.dwSize := SizeOf(TProcessEntry32);

  Process32First(HandleCaptureProcessus, UnProcessus);
  repeat
    if UnProcessus.szExeFile = NameOfProcess then
    begin
      PIDProcessus := UnProcessus.th32ProcessID;
      Break;
    end;
  until not Process32Next(HandleCaptureProcessus, UnProcessus);

  if PIDProcessus = 4294967295 then
  begin
    CloseHandle(HandleCaptureProcessus);
    exit;
  end;

  HandleProcessus := OpenProcess(PROCESS_ALL_ACCESS, False, PIDProcessus);

  EmptyWorkingSet(HandleProcessus);

  CloseHandle(HandleProcessus);
end;
{$ELSE}
procedure TForm1.MemoryFree;
begin
  //**
end;
{$ENDIF}

, , - . " " , SetProcessWorkingSetSize(), , Winapi.PsAPI. , " " . " " , , . " " 10 , 1,5 . , , , "Out of memory". , -.

-1

, :

(WebBrowser.Document as IPersistStreamInit).InitNew;
-2
source
procedure TForm1.FreeMemory;
begin
    if Win32Platform = VER_PLATFORM_WIN32_NT then
    SetProcessWorkingSetSize(GetCurrentProcess, $FFFFFFFF, $FFFFFFFF);
end;

and call him from time to time

FreeMemory;
-2
source

All Articles