我无法弄清楚如何检测静态或甚至动态链接的DLL中的内存泄漏。我只是想检测DLL中的泄漏,我不想在DLL和应用程序之间共享内存管理器。此外,该DLL是与运行时包联如何配置FastMM来检测DLL中的内存泄漏
我的示例DLL看起来是这样的:
library dll;
uses
fastmm4,
System.SysUtils,
System.Classes;
{$R *.res}
procedure MyInit; stdcall;
Begin
TObject.Create;
End;
exports MyInit;
begin
end.
应用DPR:
program app;
uses
//fastmm4,
Vcl.Forms,
main in 'main.pas' {Form1};
{$R *.res}
begin
Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
注:如果我取消fastmm4,比我能检测由应用程序(TStringList.Create)引起的memleak,但不是DLL中的泄漏。
并在应用程序主机:
unit main;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
LDLLHandle: HModule;
LShowProc: TProcedure;
end;
var
Form1: TForm1;
{$ifdef static}
procedure MyInit; stdcall; external 'dll.dll';
{$endif}
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
TStringList.Create;
{$ifdef static}
MyInit;
{$else}
LDLLHandle := LoadLibrary('dll.dll');
if LDLLHandle <> 0 then
begin
try
LShowProc := GetProcAddress(LDLLHandle, 'MyInit');
if Assigned(LShowProc) then
LShowProc;
finally
FreeLibrary(LDLLHandle);
end;
end;
{$endif}
end;
end.
我从FastMM希望生成报表时FreeLibrary则是所谓的,或者在程序退出,如果DLL静态加载,但没有任何反应。
在FastMM4Options.inc
我还只设置FullDebugMode和ClearLogFileOnStartup和FastMM_FullDebugMode.dll是在输出目录。
我创建了一个repository on github。我错过了什么?
奇怪...你刚刚克隆回购,并运行,它在xe3上工作? – balazs
当我建立自己的项目时,我无法再现。但我用我自己的fastmm选项。但是,我把你的项目,可以回购,现在已经解决了这个问题。 –