title: Memory management in object oriented design using C++
body: <p>I am working on a project which basically involves parsing and storing information about a large set of directories and files and gives me a summary of the number of files that were newly added (More like a 'File Sniffer').</p>
  
  <p>The result of my program is that when I run it on say some 30 GB of data, I see the memory (working set) being allocated grow up to 700,000 K (memory leak). </p>
  
  <p>In, my code, I am using quite a lot of object creation and destruction. The most used object is quite heavy. </p>
  
  <p>Any suggestions as what could be done to reduce the memory usage. Please let me know if anything is unclear.</p>
  
  <p>The main part of the code is something like this: </p>
  
  <pre><code>void analyzeHelper(std::string path){
      directory *dir=new directory();
      if(!dir-&gt;DirectoryExists(path))
          return;
      dir-&gt;SetCurrentDirectory(path);
      summary=new Summary();                        // Heavy class
      for(size_t i=0;i&lt;dir-&gt;GetDirectories("*.*").size();i++)
          summary-&gt;addChild(dir-&gt;GetDirectories("*.*")[i]);
      for(size_t i=0;i&lt;dir-&gt;GetFiles().size();i++)
          summary-&gt;addFile(Path&lt;std::string&gt;::toLower(dir-&gt;GetFiles()[i]));
      summary-&gt;setLocation(path);
      delete dir;
      compare(); //  here I run a comparision of the same directory with its previous version
      createMetadata(); // create an xml file to store the current version
      int size=summary-&gt;childSize();
      std::vector&lt;std::string&gt; _children=summary-&gt;getChildren();
      delete summary;
      for(int i=0;i&lt;size;i++)
      {
          FileSniffer *f=new FileSniffer(xmlroot);
          f-&gt;setRoot(dirRoot,path,remroot);
          f-&gt;analyzeHelper(_children[i]);
          delete f;
      }
  </code></pre>
  
  <p>}</p>
  
  <p><strong>A related question: How bad is it to keep copying vectors? (As I am doing with '_children' in the code)</strong></p>