title: High CPU and Memory Consumption on using boost::asio async_read_some
body: <p>I have made a server that reads data from client and I am using boost::asio async_read_some for reading data, and I have made one handler function and here _ioService->poll() will run event processing loop to execute ready handlers. In handler _handleAsyncReceive I am deallocating the buf that is assigned in receiveDataAsync. bufferSize is 500. 
  Code is as follows: </p>
  
  <pre><code>bool 
  TCPSocket::receiveDataAsync( unsigned int bufferSize )
  {
      char *buf = new char[bufferSize + 1];
  
      try
      {
          _tcpSocket-&gt;async_read_some( boost::asio::buffer( (void*)buf, bufferSize ), 
                                       boost::bind(&amp;TCPSocket::_handleAsyncReceive, 
                                                      this,
                                                      buf,
                                                      boost::asio::placeholders::error,
                                                      boost::asio::placeholders::bytes_transferred) );
  
              _ioService-&gt;poll();
  
      }
      catch (std::exception&amp; e)
      {
          LOG_ERROR("Error Receiving Data Asynchronously");
          LOG_ERROR( e.what() );
          delete [] buf;
          return false;
      }
  
      //we dont delete buf here as it will be deleted by callback _handleAsyncReceive
      return true;
  }
  
  
  void 
  TCPSocket::_handleAsyncReceive(char *buf, const boost::system::error_code&amp; ec, size_t size)
  {
      if(ec)
      {
          LOG_ERROR ("Error occurred while sending data Asynchronously.");
          LOG_ERROR ( ec.message() );
      }
      else if ( size &gt; 0 )
      {
          buf[size] = '\0';
          LOG_DEBUG("Deleting Buffer");
          emit _asyncDataReceivedSignal( QString::fromLocal8Bit( buf ) );
      }
      delete [] buf;
  }
  </code></pre>
  
  <p>Here the problem is buffer is allocated at much faster rate as compare to deallocation so memory usage will go high at exponential rate and at some point of time it will consume all the memory and system will be stuck. CPU usage will also be around 90%. How can I reduce the memory and CPU consumption?</p>