title: force a program to free memory allocated during a function after that function ends (C++)
body: <p>Is it possible to force a program to free memory allocated during a function after that function ends?</p>
  
  <p>The situation I have is essentially this.  I have a for loop that calls another function and does some things then returns.  This other function (myfunction in the below code) then calls a function I have no control over (otherpersonsfunction in the below code).  Every time my program calls otherpersonsfunction, the memory usage grows and doesn't go back down.  This isn't a problem if otherpersonsfunction is only called once or twice, but if myvector gets very large, then I will be calling it many times (enough to cause the server it was running on to run out of memory at least once).  I have no way of changing how otherpersonsfunction works so what I want to know is if it's possible to force the program to clear the memory allocated during the call of myfunction once that call is completed.  Is there something I could put in the for loop that would accomplish this?</p>
  
  <pre><code>for(int j = 0; j &lt; myvector.size(); j++)
  {
    //some code, then a function call
    myfunction(myvector.field1);
    //force program to free all memory allocated during execution of myfunction.
    //How do I do this?
  }
  
  myfunction(myvector.field1)
  {
    //some code, then a function call
    otherpersonsfunction(myvector.field1);
    return;
  }
  </code></pre>