开发者

Delphi forms.pas memory leak?

HI

I have a dynamic link library writting in Delphi 2006 that has forms.pas in its uses clause.

If I load the dll and then immediately unload it in a for loop, say 10000 times, the memory slowly climbs. However if I take Forms.pas out of the uses clause of the dll then the problem goes away.

The code is very simple

Here is my code for the dll:

library Project1;

uses
  Forms;

begin

end.

Here is my code for the calling application:

procedure TForm1.Button1Click(Sender: TObject);
var
  t_ImportHandle: LongInt;
  t_Index: Integer;
begin开发者_C百科
  for t_Index := 0 to 10000 - 1 do
  begin
    t_ImportHandle := LoadLibrary('Project1.dll');
    FreeLibrary(t_ImportHandle);
  end;
 end;

Is anyone else able to replicate this or know what the cause is and how to fix it?


TApplication.Create uses the MakeObjectInstance function in Classes.pas. MakeObjectInstance allocates a 4KB buffer using VirtualAlloc, but doesn't free it, so each time you load/unload the DLL it's going to leak that much. Andreas Hausladen used to have a blog post about it, but it looks like he's taken it down. There's a fix posted on CodeCentral, and it's also included as part of Andreas's VCL Fix Pack package.


Maybe this is not a leak but a memory manager fragmentation issues.

Why don't try using FastMM advanced logging and see if there is a leak indeed.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜