title: Confused about deleting dynamic memory allocated to array of struct
body: <p>I'm having a memory leak issue and it's related to an array of structs inside a class (not sure if it matters that they're in a class).  When I call delete on the struct, the memory is not cleared.  When I use the exact same process with int and dbl it works fine and frees the memory as it should.</p>
  
  <p>I've created very simple examples and they work correctly so it's related to something else in the code but I'm not sure what that could be.  I never get any errors and the code executes correctly.  However, the allocation / deallocation occurs in a loop so the memory usage continually rises.</p>
  
  <p>In other words, here's a summary of the problem:</p>
  
  <pre><code>struct myBogusStruct {
      int bogusInt1, bogusInt2;
  };
  
  class myBogusClass {
      public:
         myBogusStruct *bogusStruct;
  };
  
  void main(void) {
  
      int i, arraySize;
      double *bogusDbl;
      myBogusClass bogusClass;
  
      // arraySize is read in from an input file
  
      for(i=0;i&lt;100;i++) {
          bogusDbl = new double[arraySize];
          bogusClass.bogusStruct = new myBogusStruct[arraySize];
  
          // bunch of other code
  
          delete [] bogusDbl; // this frees memory
          delete [] bogusClass.bogusStruct; // this does not free memory
      }
   }
  </code></pre>
  
  <p>When I remove the bunch of other code, both delete lines work correctly.  When it's there, though, the second delete line does nothing.  Again, I never get any errors from the code, just memory leaks.  Also, if I replace arraySize with a fixed number like 5000 then both delete lines works correctly.</p>
  
  <p>I'm not really sure where to start looking - what could possibly cause the delete line not to work?</p>