Memory Management
Delphi applications are Windows native applications — they run directly on a Windows PC without needing a runtime library such as .NET Framework or Java. Each Delphi executable is a set of machine code instructions that run natively on the CPU, unlike .NET or Java applications which require a translator to convert opcodes to CPU machine code first. Here we focus on memory management differences between native Delphi applications and managed-code platforms such as .NET and Java.
Frameworks like .NET and Java include sophisticated memory managers with built-in garbage collectors. A garbage collector automatically manages object lifetime: you create objects and the runtime destroys them when they are no longer needed. This reduces the developer’s burden for manual memory management.
Delphi does not have a full garbage collector. Developers must take care to destroy objects they create dynamically in code. Delphi does provide limited automatic disposal mechanisms (for example, automatic reference counting used with Interfaces), but these are not a complete substitute for a garbage collector. You do not need to manage objects created at design-time (forms, frames, data modules, components, controls), but you must manage dynamically created objects.
Proper memory management is critical for web applications and must be handled carefully. Desktop VCL applications often have short lifetimes (typically a few hours) and modern client machines have several gigabytes of RAM, so memory leaks can remain hidden. Web application servers are designed to run indefinitely; small leaks per session can accumulate and eventually cause server instability or crashes. Extra care is required when porting legacy VCL code to uniGUI.
When porting or developing server-side (web) applications, ensure legacy VCL code is free of memory leaks. In Delphi you can enable leak reporting easily by adding a single line to the project file, for example:
begin
{$ifdef UNIGUI_VCL}
// add this line to report memory leaks
ReportMemoryLeaksOnShutdown := True;
Application.Initialize;
TUniServerModule.Create(Application);
Application.Run;
{$endif}
end.For more detailed information about memory issues and debugging/detection methods, see: Using FastMM in Full Debug Mode.