FastMM does wonders because it catches ALL memory leaks in your program and in most cases also detects memory corruption and access on objects that have been already freed.In the DPR file of your projects do this:
program MyProject;
uses
FastMM4, <--------- FastMM ALWAYS on the first line
Forms,
FormMain in 'FormMain.pas' {frmMain};
To use FastMM, just switch to debug mode, build and run your program. When you close it, FastMM will generate a report where it lists all memory leaks (if any) and the trace back to them. In Project’s Options you need to have Stack Frames activated and Map File set on ‘Details’.
Requirements:
FastMM requires a MAP file. Activate it in your Project Options.
Switching FastMM to Full Debug Mode
By default, memory leak checking is enabled only if the application is being run inside the debugger. On shutdown FastMM will report the memory leaks – if any.
To activate additional debugging features, FastMM needs to be switches to FullDebugMode. When FullDebugMode is enabled then the FastMM_FullDebugMode.dll library will be required by the application, otherwise not.
The DLL is already delivered in the FastMM Zip file from GitHub.
- Download FastMM source code from: com/pleriche/FastMM4
- Unzip to a convenient folder, like “C:\FastMM4”.
- Overwrite the inc file that comes into the zip file with the modified .inc file provided with the book (see Demo projects\ FastMM4Options.inc). This modified inc file activates a few switches like: EnableMemoryLeakReporting, LogMemoryLeakDetailToFile, FullDebugMode.
- Add the path (C:\FastMM), into the IDE (Library Paths).
- Copy “C:\FastMM\FullDebugMode_DLL\Precompiled\FastMM_FullDebugMode.dll” to “C:\Delphi12 \bin\”
- Copy “C:\FastMM\FullDebugMode_DLL\Precompiled\FastMM_FullDebugMode64.dl’” to “C:\Delphi12 \bin64\”
- Compile the program in Debug mode (enable the Map file)
Alternatively, you can copy the DLL next to the exe file you want to debug.
You can also use a tool called FastMM4Options.exe (do a Google search for it) to switch between the debug mode and the release mode. Even better, you can generate two configurations files (one for debug and one for release) with FastMM4Options and use a BAT script to instantly switch between them.
This is an excerpt. For an in-depth article see this page: https://gabrielmoraru.com/everything-you-need-to-know-about-delphi-fastmm/