title: why boost::bind with deleted object is working?
body: <p>Look at this code :</p>
  
  <pre><code>#include &lt;asio.hpp&gt;
  #include &lt;boost/bind.hpp&gt;
  #include &lt;boost/function.hpp&gt;
  
  #include &lt;iostream&gt;
  using namespace std;
  
  class acceptor
  {
  private:
      asio::ip::tcp::acceptor * a;
      asio::io_service &amp;_service;
      asio::ip::tcp::endpoint ep;
  public:
      acceptor(asio::io_service &amp;service, unsigned int port)
          :_service(service), ep(asio::ip::tcp::v4(), port)
      {
          try {
              a = new asio::ip::tcp::acceptor(service, ep);
          }
          catch (asio::system_error &amp;e) {
              cout &lt;&lt; e.what() &lt;&lt; endl;
          }
          continueAccept();
      }
  
      ~acceptor() {
          delete a;
          cout &lt;&lt; " destroy " &lt;&lt; endl;
      }
  
      void continueAccept() {
          cout &lt;&lt; "start accepting ..." &lt;&lt; endl;
          boost::shared_ptr&lt;asio::ip::tcp::socket&gt; ptr(new asio::ip::tcp::socket(_service));
          a-&gt;async_accept(*ptr, boost::bind(&amp;acceptor::handleAccept, this, ptr, asio::placeholders::error));
      }
  
      void handleAccept(
          boost::shared_ptr&lt;asio::ip::tcp::socket&gt; &amp;socket,
          const asio::error_code &amp;e)
      {
          if (e == asio::error::operation_aborted) {
              cout &lt;&lt; "handler is called by error_code : " &lt;&lt; e.message() &lt;&lt; endl;
          }
      }
  
      void close() {
          cout &lt;&lt; "close is called ..." &lt;&lt; endl;
          a-&gt;close();
      }
  };
  
  int main(int argc, char *argv[]) {
      asio::io_service service;
      acceptor *aa = new acceptor(service, 8899);
  
      service.poll();
      service.reset();
  
      delete aa;
  
      service.poll();
      service.reset();
  
      return 0;
  }
  </code></pre>
  
  <p>the output is :</p>
  
  <ul>
  <li>start accpting ...</li>
  <li>destory</li>
  <li>handler is called by error_code : operation Aborted</li>
  </ul>
  
  <p>when I delete the aa object in main method, the asio::ip::tcp::acceptor on destructor of aa object call his close and the asynchronous operation will call with asio::error::operation_aborted.</p>
  
  <p>Now, after delete, call a method like acceptHandler on aa deleted object can't cause a <strong>crash</strong> or bad use memory, but is expected. Of course, I test the program with valgrind memory analyzer for possible error, but no error exists.</p>
  
  <p>Question: why the program works currectly while calling a function on deleted object by boost?</p>