I noticed that alot of IntraWeb users are using Delphi’s default memory manager. Unfortunately this is not the best choice for server type applications.
Frequent creation and destruction of a lot of objects may lead to a
fragmented memory heap if you are using the default memory manager (MM), that
comes with Delphi. This MM was just not designed to handle applications that use
GetMem and FreeMem very frequently and in maybe odd orders. For most desktop
applications this won’t become a real issue for at least two reasons:
-
Desktop applications have a limited runtime, worst case is you
start then at 8am, and close them down at 5pm Well I know, not everybody works
8-5
-
Even if you leave your desktop application running for multiple
days, because you never shut down down your PC, its not very likely that
“normal” applications will create/destruct objects frequently
enough.
If you are creating server type applications (like IntraWeb
applications for example), then two things change:
-
Usually servers run 24/7 and you don’t want them to get
restarted frequently -
A server type application may server hundreds or maybe
even thousands of users daily
This will produce much more memory traffic and depending on
the application and what it does, it might create/destruct zillions of
objects each day. IntraWeb for example creates (and destructs) one
object instance per HTML tag on every page. All this may put a very high load
onto the memory manager. Depending on the order of how the objects are
created and destructed, i.e. how the memory is acquired and freed, this may lead
to the situation of “pseudo-memory-leaks”.
Even if you correctly free every object instance, at a certain
point the usable memory may decrease majorly, because the “holes” in
the memory heap are too small to be used. And due to the management overhead,
the process of acquiring/freeing memory will get slower and slower.
A real-world example:
Our support news server (ElkNews) at Atozed is self-implemented
(using Indy of course),
and it used to work reliable until we added some features and changed its back
end database. After 2-3 days maximum, we found that Windows’ Process
Manager showed more than 1GB of memory used by ElkNews. So we thought, ok
- some of the new features must have a memory leak.
And we started searching and debugging …
… but nothing could be found!
Then we realized that by exchanging the database, the whole memory
access structure might have changed, and we tried a memory manager replacement.
And guess what? Max. memory used is like 150-200MB after serveral weeks of
up-time. And at least subjective the server felt faster.
Somehow nobody thought of this, even though we knew that most of our
IntraWeb customers who are developing bigger IntraWeb applications are using a
MemoryManager replacement.
My general advice is this:
Always use a memory manager replacement if
you are developing a server type application! IntraWeb applications should never
be deployed without using a MemoryManager replacement.
What Memory Manager Replacement to use?
There are free and commercial solutions. I don’t get paid for
promoting a special MM, so just take this as an yet incomplete, but
“working” list of replacement MM’s:
-
Commercial
-
Free
-
We will be shipping RecyclerMM with IW
8.0, including demo.





Entries (RSS)