Free Pascal has a built in mechanism to detect memory leaks. There is a plug-in unit for the memory manager that analyses the memory allocation/deallocation and prints a memory usage report after the program exits.
The unit that does this is called heaptrc. If you want to use it, you should include it as the first unit in your uses clause. Alternatively, you can supply the -gh switch to the compiler, and it will include the unit automatically for you.
After the program exits, you will get a report looking like this:
The output of the heaptrc unit is customizable by setting some variables. Output can also be customized using environment variables.
You can find more information about the usage of the heaptrc unit in the Unit Reference.