Thanks once more, last reply cleared a few more things.
You're welcome.
With regards to the MemoryManager, i was referring to this guy:
https://www.freepascal.org/docs-html/prog/progsu174.html
I take that as meaning you'd like to have some assistance from the compiler to simplify/streamline memory management for you. That's quite reasonable, it's what the majority of programmers go for but, there is a price to pay for that convenience. (more on that follows.)
The real problem will come with multiple threads.
And it can easily become a problem in a single threaded program. The real problem is that, in any somewhat complex program, even a single thread one, depending on what some parts of the code need, memory should be managed a certain way. This leads to the optimal ways being different for different parts of the code. Just about any method that attempts to cater to all different needs is going to fall short in one way or another.
If you have any other hints to add let me know.
I'll tell you what I do but, you'll need to "customize" it for your program's needs. First, I rarely allocate heap memory. If a heap is needed by some part of the program, that part of the program is then responsible for creating its own heap (HeapCreate in Window) and destroying it when it is no longer needed. That way, no critical sections are needed to read/write the heap because the heap is private to that piece of code. Very often, there is no need to individually free blocks, instead everything is freed at once when the heap is destroyed. No memory leaks that way.
More often than not, my programs have a number of blocks of VirtualAlloc-ed memory blocks each of which is written to by, ideally, only one easily identifiable block of code. Also, quite often a program needs to make some data available, for reading only, to other parts of the program. That's another block (the program's core constant data) and, once setup, it becomes _read_only_ (set it up and freeze it, VirtualProtect it in Windows.) If "foreign" parts of the program need to write to it (something to be avoided but sometimes either unavoidable or avoiding it would significantly complicate the code) then that part of the code (usually a unit) provides specific interfaces to carry out those specific actions (nothing general, everything very specific, to prevent undesirable side-effects.)
The above makes it obvious that I don't rely in any way on the compiler to do memory management. It's more work on my part but, the performance, maintainability and debug-ability of the code is vastly better than what could be had using the compiler's facilities (and by compiler, in this case, I mean, _any_ compiler, not just FPC.)
I realize that most programmers don't want to go through that much additional work and will choose to have the assistance of the compiler.