title: D: Guaranteed Destruction
body: <p>I'm reading Andrei Alexandrescu's <em>The D Programming Language</em> and found this nugget in the tear-down sequence:</p>
  
  <blockquote>
    <p>...D assumes the exiting the application will <em>de facto</em> free all resources associated with it, so it does not invoke any destructor.</p>
  </blockquote>
  
  <p>This works great for memory resources, but what about things like network sockets, custom hardware, file handles, etc.? Is there a way to guarantee that my destructor is <em>always</em> called? Alternatively: Does D provide a better way of handling these things (and I'm stuck in a C++ mindset)?</p>