我不知道如何检测静态或动态链接的DLL中的内存泄漏。我只想检测DLL中的泄漏,而且我不想在DLL和应用程序之间共享内存管理器。此外,该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)引起的内存泄漏,但无法检测到 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位于输出目录中。
我创建了一个在github上的存储库repository on github。我缺少什么?