静的または動的にリンクされた 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.
dll が静的に読み込まれている場合、FreeLibrary が呼び出されたとき、またはプログラムの終了時に FastMM からレポートが生成されることを期待していますが、何も起こりません。
さらに、FullDebugModeとClearLogFileOnStartupFastMM4Options.inc
を設定しただけで、FastMM_FullDebugMode.dllが出力ディレクトリにあります。
github にリポジトリを作成しました。私は何が欠けていますか?