The memory manager code resides in System.pas and GetMem.inc, and as such, is compiled with every application. This is not normally a problem, but in applications using DLLs also written in Delphi, this has certain implications: since a DLL is a separately compiled application, it receives its own copy of the memory manager, and thus a separate heap. This is the most important thing to remember: each distinct application, whether an .exe or .dll, manages its own heap. All subsequent problems arise simply from having one exe/dll mistakenly manage a piece of memory that does not live in its own heap.
On the next page, find out about heaps, and why the sentance "...pass string information using PChar or ShortString parameters." can be misleading... Whenever you need to use (create) an object in Delphi, you need to free the memory it consumed (once no longer needed). Surely, the try / finally memory guarding blocks can help you prevent memory leaks; it's still up to you to safe guard your code.
A memory (or resource) leak occurs when the program loses the ability to free the memory it consumes. Repeated memory leaks cause the memory usage of a process to grow without bounds. Memory leaks are a serious problem - if you have a code causing memory leak, in an application running 24/7, the application will eat up all the memory available and finally make the machine stop responding.
Next page >
The solution > Page 1, 2
GC is not "all mighty" - if you are using "external" resources, like database connections or network resources, you are still responsible for freeing "unmanaged" (or external) resources. The framework can track when the unmanaged resource needs to be terminated, but it does not have information on how to terminate the resource and free up the memory. In order to force the developer to free its resources, any class that operates on "unmanaged" resources must implement the Dispose (made it public) method of the IDisposable interface. In general, your implementation of the Dispose method should release all the resources that an object owns (with a call to "inherited Dispose").
Danni :British Columbia Canada