我無法弄清楚如何檢測靜態或甚至動態鏈接的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選項。但是,我把你的項目,可以回購,現在已經解決了這個問題。 –