Vandrovnik 222 Posted Monday at 08:38 PM Hello, Please is it possible to have memory manager in Delphi 12.3 to call my routine when it is unable to allocate new block of memory? My routine would release some memory (cache of bitmaps) and memory manager should try again, without raising an exception. Or is there another way of creating a cache as big as possible, but without limiting "normal" operation of the application? 1 Share this post Link to post
Remy Lebeau 1600 Posted Monday at 09:41 PM (edited) 3 hours ago, Vandrovnik said: Please is it possible to have memory manager in Delphi 12.3 to call my routine when it is unable to allocate new block of memory? There is no callback in the Memory Manager. If it can't allocate memory, it will raise an exception. Period. If you to customize the behavior, you can provide your own allocation function using SetMemoryManager(), then your function can do whatever you want. But, know that there can be only 1 Memory Manager installed, so for instance if you want to use FastMM or other 3rd party Memory Manager along with your own, you will have to chain them together manually. --- UPDATE: actually there is a callback - the System.ErrorProc callback. If the Memory Manager fails to allocate, ErrorProc() will be called if assigned, specifying ErrorCode=reOutOfMemory. A default error handler is installed by the SysUtils unit, and it raises an EOutOfMemory exception. If no ErrorProc is assigned, the calling process is Halted instead. So, you could assign your own ErrorProc if you want to do something different, however by the time the Memory Manager calls ErrorProc(), it is too late to retry the allocation. If you provide your own allocation function using SetMemoryManager() instead, then you can do your own re-allocation attempt if you want to. Edited yesterday at 12:35 AM by Remy Lebeau 1 1 Share this post Link to post