title: unique_ptr .release & .reset unexpected deleter behavior
body: <p>I'm experimenting with smart pointers and experiencing a problem with the <code>unique_ptr</code>. What sparked this is that in VS2013 I am using <code>.release()</code> in a class destructor and it's not releasing (using <code>TRACE</code>) yet it is with <code>.reset</code>. 
  I have some sample code at the following URL: <a href="http://ideone.com/0aWEzj" rel="nofollow">IDEOne Example Code</a></p>
  
  <p>I've created a class containing two <code>unique_ptr</code> members. These members get assigned in the constructor and in theory, according to smart pointer theory as I understand it, should get <code>delete</code>d automatically. They are assigned a custom struct as a custom deleter, as defined below:</p>
  
  <pre><code>struct Deleter
      {
      void operator()(TCHAR* p) const
      {
          std::cout &lt;&lt; "Deleter deleting .." &lt;&lt; p &lt;&lt; '\n';
          delete[] p;
      }
  };
  </code></pre>
  
  <p>The <code>unique_ptr</code> members are declared as:</p>
  
  <pre><code>unique_ptr&lt;TCHAR[], Deleter&gt; szMySimpleString;
  unique_ptr&lt;TCHAR[], Deleter&gt; szMySimpleStringLeak;
  </code></pre>
  
  <p>the <code>unique_ptr</code> members are then defined in the constructor of a class as:</p>
  
  <pre><code>    szMySimpleString = unique_ptr&lt;TCHAR[], Deleter&gt;(new TCHAR[255], Deleter());
      szMySimpleStringLeak = unique_ptr&lt;TCHAR[], Deleter&gt;(new TCHAR[255], Deleter());
      strcpy(this-&gt;szMySimpleString.get(), "szMySimpleString");
      strcpy(this-&gt;szMySimpleStringLeak.get(), "szMySimpleStringLeak");
  </code></pre>
  
  <p>When this class is deleted, I have the destructor running <code>.release()</code> in one example, <code>.reset()</code> in another. Each has behavior that I wouldn't expect. <code>.release()</code> is running the deleter on the wrong <code>unique_ptr</code> while <code>.reset</code> runs the deleter on both <code>unique_ptr</code>'s.</p>
  
  <p>Please see the full code at the link at the beginning of this question (Note: There are 3 commented-out areas to run one at a time to see each effect).</p>
  
  <p>If I run:</p>
  
  <pre><code>szMySimpleStringLeak.release();
  </code></pre>
  
  <p>I get the results: </p>
  
  <pre><code>    Doing Stuff ...
      Contents of szMySimpleString: szMySimpleString
      Contents of szMySimpleStringLeak: szMySimpleStringLeak
  
      MyStupidClass Destructor running...
      Deleter deleting ..szMySimpleString
  </code></pre>
  
  <p>If I run:</p>
  
  <pre><code>szMySimpleString.release();
  </code></pre>
  
  <p>I get the results:</p>
  
  <pre><code>Deleter deleting ..szMySimpleStringLeak
  </code></pre>
  
  <p>and if I run:</p>
  
  <pre><code>szMySimpleString.reset();
  </code></pre>
  
  <p>I get the results:</p>
  
  <pre><code>    MyStupidClass Destructor running...
      Deleter deleting ..szMySimpleString
      Deleter deleting ..szMySimpleStringLeak
  </code></pre>
  
  <p>I'd appreciate any input to why this behavior is unexpected (or rather why I should expect it).</p>
  
  <p>Thanks!</p>