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. Do not include this unit in your uses clause directly. Instead, supply the -gh switch to the compiler, and it will include the unit automatically for you, in the correct place.
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.