ShareMem unit in Delphi - ablealias/Delphi GitHub Wiki
When using a DLL, you must be careful about dynamic memory. Any memory allocated by a DLL is freed when the DLL is unloaded
. Your application might retain pointers to that memory, though which can cause access violations or worst problems if you're not careful. The simplest solution is to use the ShareMem
unit as the first unit in your application and in every library the application loads. The ShareMem unit redirects all memory requests to a single DLL (BorlandMM.dll
), which is loaded as long as the application running. You can load and unload DLL without worrying about dangling pointers.