Delphi has a nice feature (since version ??) to check whether you leak some memory in your project. All you have to do is set the ReportMemoryLeaksOnShutDown property to true in your project file.
begin
ReportMemoryLeaksOnShutdown := true;
Application.Initialize;
If you forget to free an object you will get an unexpected memory leak exception when you close your application.
This is nice, however we always release allocated memory, don't we?;-)
Although it is nice to know that you leak some memory the messagebox does not help us to find out where it happens. It only reports the type of object, and the spilled memory in bytes.
In the marketplace there are several tools that can be used to signal memory leaks. One in particular, which I am evaluating right now, is Eurekalog.
You can use this tool to catch exceptions and memory leaks in your application. A detailed log file, with call stack, will tell you exactly the location (unit and linenumber) in the source of the unfreed object. Double clicking a line in the call stack opens the unit at that line in the IDE.
Another nice feature of Eurekalog is that you can activate it within your application, so that whenever your user hits an unexpected exception, or memory leak he/she can send the report to you by e-mail or even sent it to your bug tracking system.
The Eurekalog log file for the above memory leak looks like this:
Although we always free memory, use the try...finally construct, you will leak memory sooner or later. Tools like Eurekalog can help you tracking them down easily. Do you know more sophisticated tools, like Eurekalog, to track down memory leaks?