title: C++ : Can't free all memory in struct
body: <p>I have some trouble with free memeory allocated by C++ struct in some specific situations.
  Here is my code.</p>
  <pre><code>struct PixelPatch
  {
      float* weight;
      float* texels0;
      float sq0;
  };
  int main()
  {
      int num_texels = 30;
      PixelPatch* patches = new PixelPatch[4000000];
      for(int i = 0; i &lt; 4000000; i++)
      {
          patches[i].weight = new float[num_texels];
          patches[i].texels0 = new float[num_texels];
          for(int j = 0; j &lt; num_texels; j++)
          {
              patches[i].weight[j] = j;
              patches[i].texels0[j] = j;
          }
      }
      for(int i = 0; i &lt; 4000000; i++)
      {
          delete []patches[i].weight;
          delete []patches[i].texels0;
      }
      delete []patches;
      return 0;
  }
  </code></pre>
  <p>I use <code>htop</code> to monitor the memory occupation.
  If <code>num_texels</code> is greater than 30, all memory is freed correctly.<br />
  However, in the situation that <code>num_texels</code> is <code>&lt;= 30</code>, the following code</p>
  <pre><code> delete []patches[i].weight;
   delete []patches[i].texels0;
  </code></pre>
  <p>are not functional, and memory usage has not changed. On the other hand, <code>delete []patches</code> is not affected by <code>num_texels</code> and always works.</p>
  <p>If I use the <code>Debug</code> compilation mode in CMake, the 'magic number' of <code>num_texels</code> changes to 32. Greater than 32, works fine; less than 32, fails.</p>
  <p>My working environment is Ubuntu 20.04 + gcc9 + C++11.</p>