Delphi XE2中的DCEF内存泄漏

时间:2017-10-21 11:33:52

标签: delphi memory-leaks tchromium

我安装了以下版本的DCEF3 https://github.com/hgourvest/dcef3

我启动了一个新的VCL应用程序并删除了Chromium组件。如果我运行此应用程序,我没有错误,但如果我添加以下行:

procedure TForm2.Button3Click(Sender: TObject);
begin
  Chromium1.Load('http://www.google.com');
end;

关闭应用程序时,我有两个内存泄漏。

我试图将Chromium1.Load部分移动到应用程序的另一部分但内存泄漏仍然存在

以下是MadExcept的内存转储

allocation number: 1990
program up time: 529 ms
type: GetMem
address: $845afb0
size: 80
access rights: read/write

main thread ($cb0):
671cd312 madExcept32.dll madExceptDbg    1603 GetMemCallback
00404538 MyBrowser.exe   System           290 @GetMem
0059ad91 MyBrowser.exe   ceflib         12986 TCefBaseOwn.CreateData
0059e880 MyBrowser.exe   ceflib         15920 TCefClientOwn.Create
005ab4cc MyBrowser.exe   cefgui           648 TCustomClientHandler.Create
005aff37 MyBrowser.exe   cefvcl           798 TVCLClientHandler.Create
005b03b2 MyBrowser.exe   cefvcl           891 TCustomChromium.GetClientHandler
005b009f MyBrowser.exe   cefvcl           830 TCustomChromium.Create
00478fa5 MyBrowser.exe   System.Classes       CreateComponent
004791d0 MyBrowser.exe   System.Classes       TReader.ReadComponent
00479481 MyBrowser.exe   System.Classes       TReader.ReadDataInner
004793c0 MyBrowser.exe   System.Classes       TReader.ReadData
0047f91d MyBrowser.exe   System.Classes       TComponent.ReadState
004f7aa3 MyBrowser.exe   Vcl.Controls         TControl.ReadState
004fc0bd MyBrowser.exe   Vcl.Controls         TWinControl.ReadState
00573bb9 MyBrowser.exe   Vcl.Forms            TCustomForm.ReadState
0047a343 MyBrowser.exe   System.Classes       TReader.ReadRootComponent
00476cde MyBrowser.exe   System.Classes       TStream.ReadComponent
00471b7f MyBrowser.exe   System.Classes       InternalReadComponentRes
00471cef MyBrowser.exe   System.Classes       InitComponent
00471d7d MyBrowser.exe   System.Classes       InitInheritedComponent
0057341a MyBrowser.exe   Vcl.Forms            TCustomForm.Create
0057df22 MyBrowser.exe   Vcl.Forms            TApplication.CreateForm
005bc649 MyBrowser.exe   MyBrowser         17 initialization
76b2ef8a kernel32.dll                         BaseThreadInitThunk

memory dump: 
0845afb0  a4 cf 45 08 4c 00 00 00 - 38 75 59 00 60 75 59 00  ..E.L...8uY.`uY.
0845afc0  90 75 59 00 f4 75 59 00 - 74 76 59 00 f4 76 59 00  .uY..uY.tvY..vY.
0845afd0  74 77 59 00 f4 77 59 00 - 74 78 59 00 f4 78 59 00  twY..wY.txY..xY.
0845afe0  74 79 59 00 f4 79 59 00 - 74 7a 59 00 f4 7a 59 00  tyY..yY.tzY..zY.
0845aff0  74 7b 59 00 f4 7b 59 00 - 74 7c 59 00 f4 7c 59 00  t{Y..{Y.t|Y..|Y.

allocation number: 1989
program up time: 529 ms
type: TVCLClientHandler
address: $845cfa4
size: 92
access rights: read/write
reference counter: 1

main thread ($cb0):
671cd312 madExcept32.dll madExceptDbg   1603 GetMemCallback
00404538 MyBrowser.exe   System          290 @GetMem
0040587a MyBrowser.exe   System          290 TObject.NewInstance
0040af04 MyBrowser.exe   System          290 TInterfacedObject.NewInstance
00405eeb MyBrowser.exe   System          290 @ClassCreate
005aff1d MyBrowser.exe   cefvcl          797 TVCLClientHandler.Create
005b03b2 MyBrowser.exe   cefvcl          891 TCustomChromium.GetClientHandler
005b009f MyBrowser.exe   cefvcl          830 TCustomChromium.Create
00478fa5 MyBrowser.exe   System.Classes      CreateComponent
004791d0 MyBrowser.exe   System.Classes      TReader.ReadComponent
00479481 MyBrowser.exe   System.Classes      TReader.ReadDataInner
004793c0 MyBrowser.exe   System.Classes      TReader.ReadData
0047f91d MyBrowser.exe   System.Classes      TComponent.ReadState
004f7aa3 MyBrowser.exe   Vcl.Controls        TControl.ReadState
004fc0bd MyBrowser.exe   Vcl.Controls        TWinControl.ReadState
00573bb9 MyBrowser.exe   Vcl.Forms           TCustomForm.ReadState
0047a343 MyBrowser.exe   System.Classes      TReader.ReadRootComponent
00476cde MyBrowser.exe   System.Classes      TStream.ReadComponent
00471b7f MyBrowser.exe   System.Classes      InternalReadComponentRes
00471cef MyBrowser.exe   System.Classes      InitComponent
00471d7d MyBrowser.exe   System.Classes      InitInheritedComponent
0057341a MyBrowser.exe   Vcl.Forms           TCustomForm.Create
0057df22 MyBrowser.exe   Vcl.Forms           TApplication.CreateForm
005bc649 MyBrowser.exe   MyBrowser        17 initialization
76b2ef8a kernel32.dll                        BaseThreadInitThunk

memory dump: 
0845cfa4  b4 fd 5a 00 01 00 00 00 - fc 1d 40 00 b4 af 45 08  ..Z.......@...E.
0845cfb4  7c aa 58 00 70 ca 58 00 - 00 00 00 00 00 00 00 00  |.X.p.X.........
0845cfc4  00 00 00 00 00 00 00 00 - 00 00 00 00 00 00 00 00  ................
0845cfd4  00 00 00 00 00 00 00 00 - 00 00 00 00 00 00 00 00  ................
0845cfe4  00 00 00 00 00 00 00 00 - 00 00 00 00 00 00 00 00  ................
0845cff4  00 00 00 00 b4 9f 5a 00 - 00 00 00 00              ......Z.....

我做错了什么?

2 个答案:

答案 0 :(得分:0)

在您的应用中尝试此操作。

关于项目来源:

Application.Initialize;
try
    Application.MainFormOnTaskbar := True;
    Application.CreateForm(TForm1, Form1);
    Application.Run;
finally
    if Assigned(form1) then
      freeandnil(form1);
end;

和本

initialization
  ReportMemoryLeaksOnShutdown := (debugHook <> 0);

finalization
  CheckSynchronize();

结果是一样的吗?

答案 1 :(得分:0)

根据your G+ thread,评论说这确实是DCEF3中的错误。

切换到DCEF4比向后端移植修复要容易得多,只看一下处理created TVCLClientHandler instance的直接复杂性:

function TCustomChromium.GetClientHandler: ICefClient;
begin
  Result := TVCLClientHandler.Create(Self, False);
end;

首先,DCEF4 does much more here

function TChromium.CreateClientHandler(aIsOSR : boolean) : boolean;
begin
  Result := False;

  try
    if (FHandler = nil) then
      begin
        FIsOSR   := aIsOsr;
        FHandler := TVCLClientHandler.Create(Self, FIsOSR);
        Result   := True;
      end;
  except
    on e : exception do
      if CustomExceptionHandler('TChromium.CreateClientHandler', e) then raise;
  end;
end;