EOutOfMemory
Delphi Programming Language
Severity: CriticalWhat Does This Error Mean?
EOutOfMemory means Delphi tried to allocate memory for a new object, array, or data structure, and the operating system could not provide it. This happens when the program has consumed all available memory — either from loading too much data, from a memory leak, or from running as a 32-bit process with its 2 GB limit reached.
Affected Models
- All Delphi versions
- 32-bit Delphi applications especially
Common Causes
- A memory leak — objects being created but never freed, slowly consuming all available memory
- Loading very large files or datasets entirely into memory at once
- Deeply recursive code that creates many objects at each level
- Running as a 32-bit application, which is limited to approximately 2 GB of virtual address space
- Creating large in-memory data structures (like TStringList, TList, or TDataSet with millions of rows)
How to Fix It
-
Enable FastMM's full debug mode. At application exit, it will report every memory allocation that was not freed, including the location in your code where it was allocated.
Set FullDebugMode and LogMemoryLeakDetailToFile in your FastMM configuration.
-
Review object creation patterns. Every object created with a constructor (TMyClass.Create) must eventually be freed. Use try/finally blocks to guarantee cleanup even when exceptions occur.
Example: MyObj := TMyClass.Create; try ... finally MyObj.Free; end;
-
If you load large files or data, process them in chunks rather than loading everything at once. For TDataSet, use FetchAll sparingly — fetch only the rows you need.
Consider using a file stream instead of loading the entire file into a TMemoryStream.
-
If you are running a 32-bit application and hitting the 2 GB limit, recompile as a 64-bit application. In Delphi IDE: Project → Options → Platforms → Add Win64.
64-bit applications can access much more memory — typically up to the full installed RAM.
-
Use a memory profiler or monitoring tool to track memory usage over time. If memory grows continuously without leveling off, you have a leak. If it spikes once on a specific operation, that operation loads too much data.
The Windows Task Manager or Process Explorer can show your program's memory usage over time.
When to Call a Professional
EOutOfMemory from a memory leak requires careful debugging. FastMM in full debug mode will show you every unreleased allocation when the program exits. For 32-bit limits, recompile as a 64-bit application to access the full system RAM.
Frequently Asked Questions
How do I know if my Delphi application has a memory leak?
Enable FastMM in full debug mode — it reports leaks at exit. You can also watch your application's memory usage in Task Manager over time. If memory grows steadily without leveling off, especially after repeated operations (like opening and closing a form), you have a leak.
Does Delphi have garbage collection like Java or C#?
No — Delphi uses manual memory management for most objects. You are responsible for creating objects with Create() and freeing them with Free(). However, Delphi automatically manages strings, dynamic arrays, and interfaces using reference counting. This hybrid approach gives you control and performance, but requires discipline.
What is the memory limit for a 32-bit Delphi application?
On 32-bit Windows: approximately 2 GB. On 64-bit Windows with a 32-bit application: approximately 2 GB by default, extendable to about 3-4 GB with the LARGEADDRESSAWARE flag. A 64-bit Delphi application can use essentially all of your installed RAM (up to the OS limit).