delphifastmm

How to use FastMM SetOptions, GetOptions and foShowMemoryLeakReport in Delphi?


program Project1;

uses
  FastMM4,
  Vcl.Forms,
  Unit1 in 'Unit1.pas' {Form1};

{$R *.res}

begin
  // Ustaw opcje FastMM4, aby włączyć raport o wyciekach
  FastMM4.SetOptions(FastMM4.GetOptions + [foShowMemoryLeakReport]);

  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.

I try to show leaks in my application but it doesn't return any message. Instead I get compiler errors:

[dcc32 Error] Project1.dpr(12): E2003 Undeclared identifier: 'SetOptions'
[dcc32 Error] Project1.dpr(12): E2003 Undeclared identifier: 'GetOptions'
[dcc32 Error] Project1.dpr(12): E2003 Undeclared identifier: 'foShowMemoryLeakReport'

Solution

  • I don't know where you got that code from, but FastMM4 (and FastMM5) does not have GetOptions() and SetOptions() functions, or a foShowMemoryLeakReport flag. So the compiler errors are correct.

    Use System.ReportMemoryLeaksOnShutdown instead.

    program Project1;
    
    uses
      Vcl.Forms,
      Unit1 in 'Unit1.pas' {Form1};
    
    {$R *.res}
    
    begin
      ReportMemoryLeaksOnShutdown := True;
    
      Application.Initialize;
      Application.CreateForm(TForm1, Form1);
      Application.Run;
    end.
    

    FastMM plugs into the RTL's memory management system. Enabling the RTL's ReportMemoryLeaksOnShutdown flag will utilize FastMM's leak reporting.