Extra destructor called in vector of class object
<pre><code>TestDelete::TestDelete(int i) {
    this-&gt;i = i;
    std::cout &lt;&lt;"TestDelete constructor for "&lt;&lt;this-&gt;i&lt;&lt;"\n";
}

TestDelete::~TestDelete() {
    std::cout &lt;&lt;"TestDelete destructor for "&lt;&lt;this-&gt;i&lt;&lt;"\n";
}

int main () {
  std::vector&lt;TestDelete&gt; pt;
  pt.push_back(TestDelete(1));
  pt.push_back(TestDelete(2));

  return 0;
}
</code></pre>

<p>The above code snippet outputs as below</p>

<blockquote>
  <p>TestDelete constructor for 1</p>
  
  <p>TestDelete destructor for 1</p>
  
  <p>TestDelete constructor for 2</p>
  
  <p><strong>TestDelete destructor for 1</strong>;</p>
  
  <p>TestDelete destructor for 2;</p>
  
  <p>TestDelete destructor for 1;</p>
  
  <p>TestDelete destructor for 2;</p>
</blockquote>

<p>I understand the implementation of <code>push_back</code> is based on copy-swap concept, due to which the constructor and destructor of the temperory object is called. But if you notice an extra call to destructor of <code>object1</code> is made.</p>

<p>Can someone explain what is happening here?</p>
