Boost logo

Boost Users :

Subject: Re: [Boost-users] Memory deallocation concerning boost::bind, boost::asio and shared_ptr
From: Norman (kradepon_at_[hidden])
Date: 2016-05-17 07:15:58

It took me a while, but i finally managed to work it out by myself.

*So to clearify things, let's make sure, that the root of my problem is
I'm developing a server application, which is meant to run for an infinit
amount of time. This application must be able to handle a lot of concurrent
incomming connections. At some point in time, there may be a peak in load,
leading to a lot of claimed memory to my application. Then after a while,
most incomming requests have been processed, causing a lot of objects to be
freed in runtime. Since the OS is in no need for memory (My application is
the only huge memory consumer on the server), all freed memory stays with my
application and can be reused at another point in time. This would be
absolutely fine with me, but some customers and administrators might
misinterpret the greater amount of constantly claimed memory as a memory
leaking application. To avoid this, i wanted to hand some of the unused
memory back to the OS manually. In my example, the bound handlers to the
*ioService* (e.g. accepting a new connection) would be freed in runtime, but
the appropriate memory won't be reclaimed by the OS. So to do this manually,
i found the following solution:

*Release unused heap memory under Linux in C/C++: int malloc_trim(size_t

The documentation can be found here
<> . Simplified
explained, this method releases unused memory from the heap to the OS, which
is exactly what i've been searching for. I'm aware that under memory
optimization aspects, the manual use of this function maybe dangerous, but
since i only want to release the memory every few minutes, this performance
issue is acceptable to me.

Thank you all for your efforts and patience!

View this message in context:
Sent from the Boost - Users mailing list archive at

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at