title: How to free memory in my Class destructor?
body: <p>OK, I suppose this question may sound too silly, but memory-management (especially in C/C++) has never been my strong point and since it's usually not a noticeable thing, I tend to overlook it. So, forgive me if all this sounds stupid. However, since my current project involves A LOT of data and processing, <strong>memory consumption easily goes above 2GB in a matter of seconds</strong> and it definitely slows the whole thing down, so... it's time I started thinking of ways how to fix it.</p>
  
  <hr>
  
  <p>So, here is my situation...</p>
  
  <p><strong>My principal class</strong> (of which I'm creating some millions of instances (which hopefully are automatically deleted, since they stop being used), so supposedly <em>this</em> is the culprit) is (roughly) this :</p>
  
  <pre><code>class MyClass
  {
      public:
          // My Constructors
          MyClass ();
          MyClass (std::string param);
  
          // My Destructor (still empty)
          virtual ~MyClass ();
  
          // Some methods
          void methodA(std::string moves);
          void methodB();
  
          //----------------------
          // My Variables
          //----------------------
          boost::array&lt;int,64&gt; arrA;
          boost::array&lt;unsigned int,13&gt; arrB;
          unsigned int key;
  
          boost::array&lt;int,3&gt; arrC;       
          int argA;
          int argB;
  };
  </code></pre>
  
  <p>And this is (roughly - actual code has been altered) how the instances of the above class are created :</p>
  
  <pre><code>vector&lt;MyClass*&gt; SomeOtherClass::getListOfObjects()
  {   
      vector&lt;MyClass*&gt; objects;
  
      for (int i=0; i&lt;MAX_OBJS; i++)
      {
            // Do some preparatory work
            objects += new MyClass();
      }
  
      return objects;
  }
  </code></pre>
  
  <p>And here's how the results of the above function are being used :</p>
  
  <pre><code>void SomeOtherClass::doSth()
  {
      vector&lt;MyClass*&gt; objs = this-&gt;getListOfObjects();
      int objsSize = objs.size();
  
      for (int i=0; i&lt;objsSize; i++)
      {
          MyClass* obj = objs[i];
  
          // Do sth with obj
  
          delete objs[i];
      }
  }
  </code></pre>
  
  <p><strong>So, my question is :</strong></p>
  
  <ul>
  <li><p>What should I do in my destructor, so that when the object is not needed anymore and thus released, all of its "subcomponents" are released too? (e.g. the 2 <code>boost::array</code>s)</p></li>
  <li><p>Is there anything wrong you notice with the approach above?</p></li>
  </ul>
  
  <hr>
  
  <p>Please let me know if there's anything else you need to know about my implementation...</p>