首页 > 解决方案 > BOOST async_send_to 导致内存泄漏 (1.71)

问题描述

在此处输入图像描述

调用 sendSync 很好,调用 sendAsync 会导致堆上升。有没有人知道可能是什么原因以及如何解决它?

void sendAsync(const std::string& message)
{   
    socket.async_send_to(
        boost::asio::buffer(message), remote_endpoint,
        [this](boost::system::error_code /*ec*/, std::size_t /*bytes_sent*/)
        {
        });
}

void sendSync(const std::string& message) 
{
    boost::system::error_code ignored_error;
    socket.send_to(boost::asio::buffer(message), remote_endpoint, 0,   ignored_error);
}


for(;;)
{
    TeleItems.SentCounter++;
    printf("Sent Telegramm : %u \n",TeleItems.SentCounter);
    sender.sendAsync( "Hi this is a telegramm" );
    std::this_thread::sleep_for(std::chrono::milliseconds(1));
}

标签: c++boostasio

解决方案


推荐阅读