Tuesday, October 6, 2020

Deleaker: Advanced Memory Leak Detection for Delphi and RAD Studio

Beginning with RAD Studio 2006, Delphi, and RAD Studio in general, greatly benefited from the addition of Fast Memory Manager, or FastMM. And one of the truly welcome additions was the global variable ReportMemoryLeaksUponShutdown, which, when set to True and a small block memory leak is detected upon your application’s shutdown, displays a dialog box that identifies what was left behind. It doesn’t identify where the leak occurred, however, only that it happened.

FastMM continues to be available in RAD Studio, and you should consider downloading the full version from SourceForge (http://sourceforge.net/projects/fastmm/) to realize the full potential of FastMM, which includes much more than just memory leak detection, including enabling the generation of a stack trace, which may provide additional information about where the leak occurred.

That said, as far as memory leaks go, sometimes you need more. Which brings me to Deleaker.

I recently had the opportunity to try out Deleaker from Softantics in my Delphi applications, and I was impressed. Deleaker is a memory leak detection tool for Windows 32-bit and 64-bit applications. It can integrate with RAD studio and Visual Studio (as well as Qt Creator), and also supports a command line interface that permits you to include Deleaker as part of your continuous integration (CI) process.

In the past I’ve relied on RAD Studio’s ReportMemoryLeaksOnShutdow to identify memory leaks, but that option only tells you that you have leaks as well as how much memory was leaked. By comparison, Deleaker, when property configured, does an amazing job of identifying the source of the leak, going so far as to identify unit names and even line numbers where the leak originated. It can also find leaks in any module, for example, WinAPI functions such as CoTaskMemAlloc. FastMM cannot find that kind of leak.

Installation is simple, and after installation a new menu item, Deleaker, appears in RAD Studio’s main menu. From that menu you can enable Deleaker for all of your applications, configure Deleaker’s options, and open the Deleaker Console.

When the installation of Deleaker is complete it displays a help file that explains how to configure RAD Studio to generate the information Deleaker needs in order to serve you. (In short, you need to turn on your compiler and linker debugging options.) This help file, which can also be displayed any time you need it from the Deleaker Console, is well written and easy to follow, and the setup in RAD Studio only requires a few easy steps.

When Deleaker is enabled, and you are running your application with debugging enabled, the Deleaker Console launches when you shutdown your application. If no leak is detected, it reports that. Alternatively, if a leak is detected, Deleaker can often identify the unit name and line number where the leak likely originated. If the leak is related to a Delphi object, Deleaker will report what class of object produced the leak. This can save you hours of time scrutinizing your code for mishandled resources.

You can also display the Deleaker Console while your application is running. This permits you to take one or more snapshots of your memory usage, so you can see what’s going on while your application is still running. The Deleaker Console also lets you compare snapshots, which permits you to see changes in memory usage over time.

The types of leaks that Deleaker can detect are extensive. Here is a list, taken from the Deleaker Help file:

Memory: memory blocks allocated by heap functions, virtual memory, OLE memory:
BSTR, SAFEARRAY, etc
GDI: HBITMAP, HDC, HPEN, etc.
User32: HICON, HCURSOR, etc.
Handles: file handles, events, mutexes, etc.
FileView: views of file mappings
ActCtxCookie: cookies of activation contexts
Fiber: fibers made by CreateFiber, etc.
CriticalSection: critical sections ((if one has called InitializeCriticalSection but
forgotten to call DeleteCriticalSection)
EnvironmentString: ANSI and UNICODE environment strings
FlsSlot: fls slots
TlsSlot: tls slots
Atom: atoms.

During development, when Deleaker is enabled, you need to run your application with debugging enabled. However, it is also possible to use Deleaker with an application that is running outside of Delphi. For example, on a machine on which Delphi is not installed. Simply copy the Deleaker Console onto the machine, and then run it (Microsoft’s .NET Framework 3.5 might need to be installed). From there you can either launch your application from the Deleaker Console, or even attach to your already running application.

You can check out Deleaker free for 14 days, after which you can buy a license. Available licenses include a home license (for personal use), a single developer license, and site licenses.

You can find the Deleaker home page at https://www.deleaker.com/

Copyright © 2020. All Rights Reserved.

Wednesday, February 12, 2020

25 Years of Communicating about Delphi

Delphi turns 25 this Friday, and I’ve been fortunate to have had a front row seat. And, in addition to being a life-long database application developer, I’ve also made a career out of sharing information about software development, through books, magazine articles, conference talks, and training seminars. In this post I want to reflect back on those heady days when Delphi first came on the scene. For those who’ve been with me on this journey, thank you. For those of you who are too young to have had this pleasure, may your careers be as rich and as rewarding as it has been for those who’ve been there the whole time.

I was a frequent member of the Borland Conference (BorCon) advisory board, and that exposed me to Delphi early in its development stage. At the time I was an associate editor and columnist for Paradox Informant Magazine, and Delphi sounded like it was going to be the compiler that we Paradox developers had been waiting for.

And it was. As my longtime friend Ann Lynnworth predicted, Delphi reduced Paradox to a mere file format. It was clear to me that Delphi was going to be a really big deal. As a result, in the pre-release times I took two steps to join the Delphi community as a charter member. I committed to Informant Group publisher Mitch Koulouris to write a monthly column for his new Delphi Informant Magazine. My column, called DBNavigator (after the Delphi component), focused primarily on database development and related issues. In that first issue I described using the Borland Database Engine from within Delphi to work with Paradox and Dbase tables. That was the first of 42 consecutive issues in which my column appeared, though I continued to be a regular contributor for the remaining years of publication.



The front cover of the premiere issue of Delphi Informant Magazine, published in May of 1995

My second commitment was to Softbite International president Kevin Smith, to write and present a two-day Delphi course if he would take it out on tour. I had been working with Softbite for some years, and was a presenter on the Paradox 5 for Windows World Tour, and wrote the material for, and presented, on the Paradox 7 for Windows World Tour. He agreed, and this new 24 city tour was known as the Delphi World Tour. It began in Columbus, Ohio on July 6th of 1995. I taught that first stop, as well as about 12 others. I believe there were two other presenters, one of them being the venerable Bill Todd. If there was another, I can’t remember who it was. They (or he) covered the remaining cities.



An ad for the original Delphi World Tour appearing in the July 1995 issue of Delphi Informant

Despite my principal work being as a Delphi developer, I continued to write and present the Delphi World Tours (the final being the Delphi 5 World Tour), and followed that with Delphi Development Seminars in conjunction with Informant Communication Group (one year only), several years of the Borland Developer Days (Europe, in conjunction with Desktop Associates), and then Delphi Developer Days, which I started with my wife, Loy Anderson. Delphi Developer Days ran from 2001 (where the first stop on the tour, Arlington, Virginia, had to be cancelled after the 9/11 attacks due to the closing of Metro underground that ran past the Pentagon and the number of government attendees, whose priorities changed after that awful event) and continued through 2017.

We expanded Delphi Developer Days in 2009 by added a second presenter, which gave me the opportunity to work with four of the top Delphi professionals, all Spirit of Delphi recipients: Marco CantĂș, Bob Swart, Ray Konopka, and Nick Hodges. Thanks, guys. It was a great pleasure.

During the past 25 years I have written about and/or trained developers on every version of Delphi (including the notorious .NET only Delphi 8), and as you might imagine, I have acquired a museum-like collection of software. One of my favorites, shown here, is my original, shrink-wrapped copy of Delphi Client/Server.



A shrink-wrapped copy of the original Delphi Client/Server

I have a lot of stories that I could share about Delphi, but I think I’ll leave those for another time. I mean, there’s a real danger here. I know myself pretty well, and once I got started, I’d probably have to write an entire book, and I just don’t have the time for that right now, my being committed to a new startup.

But a particular observation comes to mind. To quote the immortal Grateful Dead, and in respect for David Intersimone’s penchant for wearing tie-dye t-shirts, I have to say “What a long strange trip it’s been.”

Let me conclude with an observation and a positive thought. Delphi is still going strong, and the latest version, Delphi Rio 10.3.3, is the best yet. So, Cheers! Here’s to the next 25 years.

Copyright © 2020. All Rights Reserved.