|
Boost Users : |
Subject: [Boost-users] Memory deallocation concerning boost::bind, boost::asio and shared_ptr
From: Norman Kradepohl (kradepon_at_[hidden])
Date: 2016-04-28 07:42:12
Hi there,
my code is allocating memory and never freeing it, even though it should
(at least in my opinion).
The header looks like this:
typedef boost::asio::ssl::stream<boost::asio::ip::tcp::socket>
sslSocket_t;
class Object {
boost::asio::io_service ioService_;
boost::asio::ip::tcp::acceptor acceptor_;
boost::asio::ssl::context context_;
void functionOne();
void functionTwo(shared_ptr<sslSocket_t>& sslSocket, const
boost::system::error_code& error)
}
And my source like this:
void Object::functionOne() {
for (int i = 0; i < 10; i++) {
shared_ptr<sslSocket_t> sslSocket(new
sslSocket_t(ioService_, context_));
acceptor_.async_accept(sslSocket->lowest_layer(),
boost::bind(&Object::functionTwo, this,
sslSocket, boost::asio::placeholders::error));
}
acceptor_.cancel();
boost::asio::io_service::work work(ioService_);
ioService_.run();
}
void functionTwo(shared_ptr<sslSocket_t>& sslSocket, const
boost::system::error_code& err) {
// Do nothing
}
So when i call *Object.functionOne()*, memory is getting allocated to
the *Object.ioService_* object, in order to be able to call the bound
asynchronous method. Then after the loop, all pending asynchronous
actions on the acceptor are getting canceled. The appropriate handler is
getting invoked as soon as *Object.ioService_.run()* is called (i've
been testing that). BUT for some reason, the allocated memory does not
get freed. I'm stuck on this problem for a while now, any hint or help
would be really appreciated.
Btw.: I'm working on debian and looking at "/proc/self/status" ->
"VmRSS" to whatch the used memory.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net