Running the Test Application

By a closer look at the application we can see that there are three different test procedures to simulate memory issues:

Memory Leaks

procedure TMainForm.UniButton1Click(Sender: TObject);
var
  P : PInt64;
begin
  // Simulate memory leak:
  // We create a memory instance for Int64, but we don't free it (memory leak)
  New(P);

  // Below call will terminate the standalone server, so we can see FastMM leak error message immediately.
  // This is done for demonstration purpose only.
  // Never call "UniServerInstance.Terminate" in your production code
  // Alternatively, you can comment below line and exit from application manually.
  UniServerInstance.Terminate;
end;

In the above event we try to simulate a memory leak by creating a PInt64 instance. Since memory leaks are only reported upon exit we terminate the application immediately to see the error message box:

clip0361

At the same time the memory leak will be logged to the FastMM log file which will be created under the same folder.

Here are the partial contents of the log file:

--------------------------------2025/5/5 16:32:07--------------------------------

Not only it reports existence of a memory leak, but also it logs the chain of methods (stack trace) which led to the memory leak:

Line 46 in file Main.pas — it shows the location in code where memory that is allocated, but has not been freed:

clip0362

Memory Corruption

The most important type of memory issues is memory corruptions where an application tries to alter a memory location which was previously freed.

clip0363

Again we can see the same error in the log file:

--------------------------------2025/5/5 16:49:50--------------------------------

The above log indicates that the memory object was allocated in code line 61:

clip0364

The block was previously freed by thread 0x5164, and the stack trace (return addresses) at the time was:

Allocated memory is disposed at line 62.

Please note that FastMM is unable to find the exact line of code where memory is altered. FastMM can only detect and report that a memory location is altered after it has been freed and reallocated.