Science, Tech, Math › Computer Science Memory Leak Notification in Delphi on Program Exit Share Flipboard Email Print monsitj / Getty Images Computer Science Delphi Programming Delphi Tutorials Advanced PHP Programming Perl Python Java Programming Javascript Programming C & C++ Programming Ruby Programming Visual Basic View More By Zarko Gajic Zarko Gajic Twitter Computer Science Expert MSCS, Computer Science, University of Osijek Zarko Gajic is experienced in SQL and has working knowledge of DB systems such as MS SQL Server, Firebird, Interbase, and Oracle. He is also proficient in XML, DHTML, and JavaScript. Learn about our Editorial Process Updated on March 10, 2018 All Delphi versions since Delphi 2006 have an updated memory manager that is faster and more feature rich. One of the nicest features of the "new" memory manager allows applications to register (and unregister) expected memory leaks, and optionally report unexpected memory leaks on program shutdown. When creating WIN32 applications with Delphi it is imperative to make sure that you free all the objects (memory) you create dynamically. A memory (or resource) leak occurs when the program loses the ability to free the memory it consumes. Report Memory Leaks on Shutdown Memory leak detecting and reporting are set to false by default. To enable it, you need to set the global variable ReportMemoryLeaksOnShutdown to TRUE. When the application is closed, if there are unexpected memory leaks the application will display the "Unexpected Memory Leak" dialog box. The best place for the ReportMemoryLeaksOnShutdown would be in the program's source code (dpr) file. begin ReportMemoryLeaksOnShutdown := DebugHook <> 0; //source "by" Delphi Application.Initialize; Application.MainFormOnTaskbar := True; Application.CreateForm(TMainForm, MainForm) ; Application.Run; end. Note: a global variable DebugHook is used above to make sure memory leaks are displayed when the application is run in debug mode - when you fit F9 from the Delphi IDE. Test Drive: Memory Leak Detection Having ReportMemoryLeaksOnShutdown set to TRUE, add the following code in the main form's OnCreate event handler. var sl : TStringList; begin sl := TStringList.Create; sl.Add('Memory leak!') ; end; Run the application in debug mode, exit the application - you should see the memory leak dialog box. Note: If you are looking for a tool to catch your Delphi application errors such as memory corruption, memory leaks, memory allocation errors, variable initialization errors, variable definition conflicts, pointer errors ... take a look at madExcept and EurekaLog Delphi Tips Navigator Date Time SQL Queries: Formatting Date Time Values for Access SQL in Delphi Force TListView's Edit Mode using a Keyboard Shortcut Cite this Article Format mla apa chicago Your Citation Gajic, Zarko. "Memory Leak Notification in Delphi on Program Exit." ThoughtCo, Jul. 30, 2021, thoughtco.com/memory-leak-notification-in-delphi-1057613. Gajic, Zarko. (2021, July 30). Memory Leak Notification in Delphi on Program Exit. Retrieved from https://www.thoughtco.com/memory-leak-notification-in-delphi-1057613 Gajic, Zarko. "Memory Leak Notification in Delphi on Program Exit." ThoughtCo. https://www.thoughtco.com/memory-leak-notification-in-delphi-1057613 (accessed June 1, 2023). copy citation