<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII"> <title>io_service::~io_service</title> <link rel="stylesheet" href="../../../boostbook.css" type="text/css"> <meta name="generator" content="DocBook XSL Stylesheets V1.73.2"> <link rel="start" href="../../../index.html" title="Asio"> <link rel="up" href="../io_service.html" title="io_service"> <link rel="prev" href="wrap.html" title="io_service::wrap"> <link rel="next" href="../io_service__id.html" title="io_service::id"> </head> <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> <table cellpadding="2" width="100%"><tr><td valign="top"><img alt="asio C++ library" width="250" height="60" src="../../../asio.png"></td></tr></table> <hr> <div class="spirit-nav"> <a accesskey="p" href="wrap.html"><img src="../../../prev.png" alt="Prev"></a><a accesskey="u" href="../io_service.html"><img src="../../../up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../home.png" alt="Home"></a><a accesskey="n" href="../io_service__id.html"><img src="../../../next.png" alt="Next"></a> </div> <div class="section" lang="en"> <div class="titlepage"><div><div><h4 class="title"> <a name="asio.reference.io_service._io_service"></a><a class="link" href="_io_service.html" title="io_service::~io_service"> io_service::~io_service</a> </h4></div></div></div> <p> <a class="indexterm" name="id847812"></a> Destructor. </p> <pre class="programlisting"><span class="special">~</span><span class="identifier">io_service</span><span class="special">();</span> </pre> <p> On destruction, the <a class="link" href="../io_service.html" title="io_service"><code class="computeroutput"><span class="identifier">io_service</span></code></a> performs the following sequence of operations: </p> <div class="itemizedlist"><ul type="disc"> <li> For each service object <code class="computeroutput"><span class="identifier">svc</span></code> in the <a class="link" href="../io_service.html" title="io_service"><code class="computeroutput"><span class="identifier">io_service</span></code></a> set, in reverse order of the beginning of service object lifetime, performs <code class="computeroutput"><span class="identifier">svc</span><span class="special">-></span><span class="identifier">shutdown_service</span><span class="special">()</span></code>. </li> <li> Uninvoked handler objects that were scheduled for deferred invocation on the <a class="link" href="../io_service.html" title="io_service"><code class="computeroutput"><span class="identifier">io_service</span></code></a>, or any associated strand, are destroyed. </li> <li> For each service object <code class="computeroutput"><span class="identifier">svc</span></code> in the <a class="link" href="../io_service.html" title="io_service"><code class="computeroutput"><span class="identifier">io_service</span></code></a> set, in reverse order of the beginning of service object lifetime, performs <code class="computeroutput"><span class="keyword">delete</span> <span class="keyword">static_cast</span><span class="special"><</span><span class="identifier">io_service</span><span class="special">::</span><span class="identifier">service</span><span class="special">*>(</span><span class="identifier">svc</span><span class="special">)</span></code>. </li> </ul></div> <a name="asio.reference.io_service._io_service.remarks"></a><h6> <a name="id848023"></a> <a class="link" href="_io_service.html#asio.reference.io_service._io_service.remarks">Remarks</a> </h6> <p> The destruction sequence described above permits programs to simplify their resource management by using <code class="computeroutput"><span class="identifier">shared_ptr</span><span class="special"><></span></code>. Where an object's lifetime is tied to the lifetime of a connection (or some other sequence of asynchronous operations), a <code class="computeroutput"><span class="identifier">shared_ptr</span></code> to the object would be bound into the handlers for all asynchronous operations associated with it. This works as follows: </p> <div class="itemizedlist"><ul type="disc"> <li> When a single connection ends, all associated asynchronous operations complete. The corresponding handler objects are destroyed, and all <code class="computeroutput"><span class="identifier">shared_ptr</span></code> references to the objects are destroyed. </li> <li> To shut down the whole program, the <a class="link" href="../io_service.html" title="io_service"><code class="computeroutput"><span class="identifier">io_service</span></code></a> function <code class="computeroutput"><span class="identifier">stop</span><span class="special">()</span></code> is called to terminate any <code class="computeroutput"><span class="identifier">run</span><span class="special">()</span></code> calls as soon as possible. The <a class="link" href="../io_service.html" title="io_service"><code class="computeroutput"><span class="identifier">io_service</span></code></a> destructor defined above destroys all handlers, causing all <code class="computeroutput"><span class="identifier">shared_ptr</span></code> references to all connection objects to be destroyed. </li> </ul></div> </div> <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> <td align="left"></td> <td align="right"><div class="copyright-footer">Copyright © 2003 - 2010 Christopher M. Kohlhoff<p> Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>) </p> </div></td> </tr></table> <hr> <div class="spirit-nav"> <a accesskey="p" href="wrap.html"><img src="../../../prev.png" alt="Prev"></a><a accesskey="u" href="../io_service.html"><img src="../../../up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../home.png" alt="Home"></a><a accesskey="n" href="../io_service__id.html"><img src="../../../next.png" alt="Next"></a> </div> </body> </html>