There is an indirect solution to the problem. I have been developing a server application for several years. Initially, we perform on-demand distribution, and as a result, after several weeks of operation, server performance deteriorates. As a workaround, we followed this approach -
Suppose you have custom classes X, Y, Z, .. that you need to allocate from the heap at runtime. Highlight n number of X objects at startup. Put all these objects in the list of free pools. Upon request, take each x object and submit it to your application. When you use, put it in the list of downloaded pools. When the application wants to release it, return it back to the list of free pools. Follow this start for Y. Z, etc.
Since you select all the necessary objects at startup and never release them back into the OS memory box until your program exits, you will not experience performance degradation caused by memory fragmentation.
source share