amgbox / baserver

Automatically exported from code.google.com/p/baserver
0 stars 0 forks source link

service_handler内存管理问题 #14

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
service_handler内存首先是通过service_handler_pool申请的,在有客户
端请求连接的时候从service_handler_pool中取出一个用于Accept,我
觉得会出现内存的泄漏,具体是这样的:Accept之后,马上会bi
nd一个读取,这时候如果我们想关闭这个连接即调用close,这�
��候由于读取事件没有发生,这个内存一直没有被正确的释放
,代码为:

  /// Handle completion of an asynchronous accept operation.
  void handle_accept(const boost::system::error_code& e,
      service_handler_ptr handler)
  {
    if (!e)
    {
      // Start the first operation of the current handler.
      handler->start();
      handler->close(); // 传入读取事件之后马上要求关闭连接
      // Accept new connection.
      accept_one();
    }
    else
      handler->close(e);
  }

这时候可以发现service_handler并没有被释放,原因在于传入读��
�事件的时候参数是service_handler_ptr,也就是说在io_service没有��
�应读取事件之前是没有办法释放service_handler内存。

BAS代码中涉及service_handler的传递都是用shared_ptr,有一种击鼓�
��花的感觉,如果在这个过程中调用close(比如服务器想主动�
��闭一个客户端,或者这个链接超时)都不能正确的释放内存

刚看代码没几天,觉得很强大!这个issue可能是我使用或者理
解出错,不过值得讨论一下这种情况

Original issue reported on code.google.com by newreds...@gmail.com on 18 Oct 2011 at 6:59

GoogleCodeExporter commented 8 years ago
看了service_handler_pool的实现,发现是我理解问题,释放后直接
调用了push_handler放回service_handler_pool

moore.xu勿怪哈,sorry!

Original comment by newreds...@gmail.com on 18 Oct 2011 at 9:06

GoogleCodeExporter commented 8 years ago
没什么,一下没留意也是很正常的事。
总体来说,使用echo_server连续运行测试了超过250万次连接,从
线程、句柄变化的情况来看,没有发现泄露的情况。

Original comment by moore...@gmail.com on 18 Oct 2011 at 10:27

GoogleCodeExporter commented 8 years ago
如何使用BAS进行文件传输?可否给个示例?

Original comment by snows...@gmail.com on 8 May 2012 at 11:26