Catching memory leaks in Delphi: a definitive list of tools

Originally published at: https://landgraf.dev/en/catching-memory-leaks-in-delphi/

Detecting memory leaks is a very important task in Delphi development. I’ve written about it before, stressing that in server applications like the ones built with TMS XData this is even more important.

With the upcoming release of Delphi 10.4 version, this will become even more relevant. A unified memory management has been promised since last year, and it looks it has arrived.

As everything in life, this change isn’t 100% good or bad, there are pros and cons in it, but one thing is clear: the way memory is managed now is the same in all platforms, so the ways to detect memory leaks in different platforms are more similar now. I personally think this is a good thing. It’s also important to note that this doesn’t necessarily mean “more leaks” in mobile platforms. The “old” (still valid when I’m writing this article) ARC mechanism also had its problems, and in my opinion harder to detect, like dealing with cyclical references.

But well, enough with this too long introduction. The humble purpose of this article is to be a definitive and up-to-date list of all tools that you can use to detect memory leaks in Delphi applications. Pointing out that memory management is unified just means that these tools are even more relevant than ever. Detecting and fixing a memory leak in Windows will help even more that your non-Windows applications will not have memory leaks as well.

So, to the list!

FastMM (Free)

![](upload://mLG2c4RBCqwKUY037dSRQJ34lgi.jpeg)

FastMM (or to be more specific, FastMM4) is the de-facto standard tool to detect memory leaks in Delphi. The reason is simple: it’s the default memory manager in Delphi, so it’s already built-in and ready to use.

Since FastMM allocates and deallocates memory in your application, who else is better to report the blocks that have not been deallocated? All that it takes to start working with it is add a single line in your project:

ReportMemoryLeaksOnShutdown := True;

And voilà, your application will report all memory leaks when it shuts down. If there are leaks at the end of your application, a dialog will be displayed showing all the leaks.

![](upload://3TYTUGq79tvq7pgxoAtKnKfSI4r.png)

All Delphi developers should add that line to their applications. Really. I don’t even know why this is not added by default in Delphi, at least wrapped by a {$IFDEF DEBUG} directive. Maybe for historical reasons.

So, if it’s built-in, default, works, why don’t we finish this article here, then? Well, there are some gotchas.

Delphi includes a stripped out version of FastMM4. It doesn’t have all the nice debugging tools you need (to know, for example, where in the code your leaked memory was allocated). To do that, you have to use the full FastMM4 version, available on the FASTMM4 public GitHub repository.

You also have to use a DLL for the full debugging features; it’s not cross-platform: it only officially works for Windows (it looks like a macOS version is available in the official repo, but I never tried it). And even though it has lots of features, to use it you have to deal with .INC files and manual configurations to make it work, which might not be comfortable for some users.

But all in all, is a great tool, the “standard” tool to get memory leaks in Delphi. (Side note: FASTMM5 has just been released. We haven’t tested it yet but it looks like it brings a great improvement in performance for multithreaded applications, we can’t wait to test it in TMS XData.)

Pros

  • Free;
  • Full source code;
  • Built-in in Delphi;
  • Easy to setup;
  • Lots of advanced features.

Cons

  • Windows only;
  • Needs external DLL for debugging features;
  • Not user-friendly to setup and use advanced features (no built-in GUI);
  • Only reports leaks on memory allocated by FASTMM itself.

LeakCheck (Free)

Delphi LeakCheck is another great option for detecting memory leaks. It’s also free, open source, and has some advantages over FastMM: it’s cross-platform, meaning you can check leaks directly in mobile and Linux applications; and it integrates very well with unit test frameworks (namely DUnit and DUnitX).

The way to get started with it is similar to FastMM: add LeakCheck unit as the first used unit in your dpr uses clause, and it will plugin and be ready to use. Setting up for unit testing is a little more complicated though, but that’s part of the game.

One small disadvantage is that to use it you are almost on your own: the project hasn’t received updates for a while (which isn’t necessarily bad since it’s working). But that means probably you won’t get much help directly from the author (I never tried, to be fair). There is also not much information about it in the web, I just found one single article that explains how to use it besides the detailed description in the official Bitbucket repository itself.

Pros

  • Free;
  • Full source code;
  • Cross-plataform;
  • Integrates well with unit testing (DUnit and DUnitX).

Cons

  • Not much information around about how to use it;
  • No recent updates, no official support;

Deleaker (Commercial)

![](upload://9rG511MXTKbZwlRKsWdnUpqFxUC.png)

Delaker is the only commercial tool in the list that is exclusively dedicated to catch memory leaks. That reflects in the product, which provides you with really nice features for detecting memory leaks.

![](upload://k5WlvzBZL8Aay7rvdnCekCnqbYl.png)

Differently from the previous two tools, and similar to the following ones, it has a friendly GUI for you to setup the environment and see the results, which can be used standalone or integrated to Delphi IDE. It can also detect way more types of memory leaks: GDI leaks, leaks of Windows USER objects and handles, leaks in Windows APIs, in 3rd party DLLs, etc. Exactly because of that, it provides options for you to easily ignore several types of leaks – if you don’t, you will get a gazillion of leaks in just a regular app execution.

Another nice feature is the ability to take snapshots of the memory allocation. This allows you to detect leaks not only during the lifetime of your whole application, but in some specific operations of it.

Pros

  • Friendly GUI that can be used standalone or integrated into Delphi IDE;
  • Detects all types of leaks;
  • Command-line tool for CI integration;
  • Memory usage snapshots;
  • Official support;

Cons

  • Paid license ($99 for Home License, $399 for Single Developer License);
  • Windows only;

EurekaLog (Commercial)

![](upload://qz6nyECylHBRY2ddII5pV7BXvCK.png)

EurekaLog is an old player. It’s been around for decades – I couldn’t find any info on their web site about when first version was released, the oldest information is for EurekaLog 4.0 which was released in 2002, simply 18 years ago.

![](upload://pxGIkQLmHcnTwnwodamToqTZtZe.png)

It’s not a tool dedicated exclusively to catch memory leaks. Instead, it has a full range of features, memory leak detection being just a “side” feature. The purpose of EurekaLog is to detect any problems in your application – exceptions, leaks, etc. – at the customer side, and report it back to you.

Thus, it’s a great tool to help you improve the quality of your software and provide good support to your customers, since you will get error and leak reports from all your customers, in different environments, doing different operations. It also helps you to find tricky bugs that only happen at customer side (you know it well, those “cannot reproduce it here” situations).

Pros

  • Detects both memory and resource leaks;
  • Leaks and errors detected at customer side can be sent automatically to you;
  • Lots of other features: bug reporting, integration with bug tracking systems, among others;
  • Official support;

Cons

  • Paid license ($149 for Professional License, $249 for Enterprise License);
  • Windows only;
  • Not many advanced features for memory leak detection;

madExcept (Commercial)

![](upload://mQspeQTkT9gKzMyjgqZU48gjnqo.gif)

I use to say that MadExcept is the “cousin” of EurekaLog. They are both available for about the same time (around 20 years or more). They share similar features. They have more or less the same purpose. And so on.

And, funny enough, there isn’t a “winner”. If you look around the web about comparisons between the two, you will never come to a conclusion on which is “better”. Customers of both products are usually satisfied, and also usually they can’t comment on the competitor because they never used it. That’s my case, actually. I’m a happy EurekaLog customer (although I don’t use it to catch memory leaks), and I never used madExcept. But it could simply be the opposite. I believe I could be well served with madExcept as well.

Thus, I considered madExcept pros and cons equal to EurekaLog’s. Maybe the only visible different is that while madExcept is cheaper (there is even a free version for non-commercial use), EurekaLog seems to be much more active and frequently updated.

Pros

  • Free for non-commercial support;
  • Detects both memory and resource leaks;
  • Leaks and errors detected at customer side can be sent automatically to you;
  • Lots of other features: bug reporting, integration with bug tracking systems, among others;
  • Official support;

Cons

  • Paid license (€ 159 for full source license);
  • Windows only;
  • Not many advanced features for memory leak detection;

AQTime Pro (Commercial)

![](upload://wCfJ7qzvUkHa7DLPEwYH1qODzXv.png)

AQTime is a top-notch tool to make your code better. It’s really high standard, offering not only an advanced memory leak detection tool (with a nice GUI, snapshots, memory tracking, resource leaks detection, among others) but also performance profiling (with both instrumenting and sampling profilers), code coverage, code analysis, among others.

![](upload://1uCSFKDBgDeTzPpuOo70ZJXfzPx.png)

It’s really awesome tool, but it has its downsides: it’s pretty expensive, and it looks in “maintenance” mode – it receives updates more or less once a year, and the news are mostly “support for the new Delphi version”. Handful bug fixes over the years, and virtually no new features. But well, it still has no equivalent tool in Delphi world when it comes to many and powerful features.

Pros

  • Detects memory, resource, GDI, handle leaks among others;
  • Real-time allocation monitor;
  • Snapshots;
  • Lots of other tools in the bundle (performance profiler, code coverage, etc.).

Cons

  • Pretty expensive ($719 for a node-locked license, $2279 for node-floating license);
  • Windows only;

Nexus Quality Suite (Commercial)

![](upload://hYezfwcrPA7jc99FNJmkf6HGitC.png)

In a similar way of EurekaLog and madExcept, I believe Nexus Quality Suite is somewhat related to AQTime. Both provide lots of tools to improve the quality of your software, and there are intersections between them.

![](upload://ry2VyCVP8d3p0o61fCj8QOqEfHg.png)

Nexus Quality suite provides memory and resource leak detectors, but also performance profilers, line timers, code coverage, and even a GUI automatic tester, among other things.

I haven’t tried the memory check tool myself, thus the pros and cons will be just based on what I see from web site:

Pros

  • Detects memory and resource leaks;
  • Official support, active support forums;
  • Lots of other tools in the package

Cons

  • Paid license (AUD 490, around $300);
  • Windows only.

DDDebug (Commercial)

From their website: DDDebug is a collection of debugging tools which contains several modules: a memory profiler, a thread viewer, a module viewer and an enhanced exception handler.

![](upload://soqjx5AdqIkcq41pOLFVFse3e6g.png)

One interesting thing I noted from DDDebug is that it has a slightly different approach, by providing memory usage and statistics instantly from inside the application. I didn’t use it but it looks like it makes it easier to find bugs in the app, by interacting with it at the same time you analyze it.

It also works with packages which is a plus, provides more functions besides just memory leak detection, and even though it’s commercial, the license price is really accessible.

Pros

  • Provides results directly inside your application, from a GUI;
  • Supports packages;
  • Official support;
  • Accessible license price (from €59).

Cons

  • Windows only;

Spider (Free)

Spider websites lists a lot of interesting features: analysis of exceptions, analysis of the realtime use of memory, analysis of memory leaks, analysis of the call stack, among others.

![](upload://qE8NVJWYhwOWT1E2IxsWGVvCTvt.png)

The thing is, from the list, is a tool I just tried once, and I got confused with the user interface and the results themselves. I couldn’t use it, but maybe that’s just me. So it’s listed here, but I can’t make any fair judgement over it.

Pros

  • Free;
  • Source code available;

Cons

  • Confusing user interface (personal opinion);

Non-Delphi Tools

In addition to the above tools that are Delphi specific, or at least also cover Delphi specifically – either integrating into source code, or in the IDE, etc. – there are also general-purpose tools for memory leak detection which can be helpful in some situations.

Valgrind (Free)

![](upload://ax9xZ3T833c2tz1oBhtBHKC1npO.png)

Valgrind is an instrumentation framework. It provides many tools in it, and you can add your own. One of the tools is memcheck, which will help you to get leaks in your application.

![](upload://tqOkAjeq6kBpPM85CmsY0mMsMU7.png)

I use it myself a lot to detect memory leaks in Linux applications, and it’s actually very simple to use: just execute valgrind and pass the application you want to test in the command-line parameter. Valgrind will launch the application and at the end of it will give you a report with detailed information including possible leaks. There are of course many command-line options you can use to log to a file, choose the size of call stack, detection level, among others.

Instruments (Free)

Apple Instruments is a powerful and flexible performance-analysis and testing tool that’s part of the Xcode tool set. Among other things, it can be used to detect leak in iOS and macOS applications. Adrian Gallero has made a nice article at TMS Software blog about how to use Instruments to detect leaks in iOS applications. It’s a little bit old post already, but I believe it’s still valid.

Conclusion

There is no winner. Each tool has their own pros and cons, and it’s interesting to note that the they are not mutually exclusive. Actually, I use several of them myself, for different purposes.

I use FastMM for my “daily” memory leak detection, LeakCheck in unit tests, Deleaker when I want to check for other types of leaks and use snapshots, EurekaLog for bug reporting in my end-user applications, AQTime for performance profiling and Valgrind for detecting leaks in Linux. As you can see, all of them are useful!

The important thing is: don’t let your application leak memory! If you are just starting with this subject, you know what to have to do now:

ReportMemoryLeaksOnShutdown := True;

Add the above line to your application and start catching leaks!

(Do you know of any other tool that should be on the list? Do you have a different opinion on the listed tools? Please comment below and share your knowledge to help make this list the definitive one. I will update it frequently as I receive new info.)