title: Memory leak in C++ function using std::swap
body: <p>I'm using qt creator and I'm having trouble with a memory leak. I've read some posts about dynamic memory allocation but from what I've seen, I can't understand why my function is accumulating something in memory.</p>
  
  <p>I'm completely sure I've pinpointed the function that causes the problem:</p>
  
  <pre><code>void CSimWindow::cloneNet(int origin, int destination)
  
      int newNumSensors = netVector[origin].getNumSensors();
      int newNumActuators = netVector[origin].getNumActuators();
      int newNumNeurons = netVector[origin].getNumNeurons();
  
      CNet newNet(newNumNeurons, 0);
      newNet.setNumSensors(newNumSensors);
      newNet.setNumActuators(newNumActuators);
  
      for (int i = 0; i &lt; netVector[origin].getNumNeurons(); i++)
      {
          ...
      }
      std::swap(newNet, netVector[destination]);
  
  }
  </code></pre>
  
  <p>I'm quite a newbie, but as I understand it, the objects created inside the function should be destroyed when it's finished. If anyone can tell me why this function causes the memory leak, I thank you in advance.</p>