title: Fail to malloc big block memory after many malloc/free small blocks memory
body: <p>Here is the code.</p>
  
  <p>First I try to malloc and free a big block memory, then I malloc many small blocks memory till it run out of memory, and I free <strong>ALL</strong> those small blocks.</p>
  
  <p>After that, I try to malloc a big block memory.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  int main (int argc, char **argv)
  {
      static const int K = 1024;
      static const int M = 1024 * K;
      static const int G = 1024 * M;
  
      static const int BIG_MALLOC_SIZE = 1 * G;
      static const int SMALL_MALLOC_SIZE = 3 * K;
      static const int SMALL_MALLOC_TIMES = 1 * M;
  
      void **small_malloc = (void **)malloc(SMALL_MALLOC_TIMES * sizeof(void *));
  
      void *big_malloc = malloc(BIG_MALLOC_SIZE);
      printf("big malloc first time %s\n", (big_malloc == NULL)? "failed" : "succeeded");
      free(big_malloc);
  
      for (int i = 0; i != SMALL_MALLOC_TIMES; ++i)
      {
          small_malloc[i] = malloc(SMALL_MALLOC_SIZE);
          if (small_malloc[i] == NULL)
          {
              printf("small malloc failed at %d\n", i);
              break;
          }
      }
      for (int i = 0; i != SMALL_MALLOC_TIMES &amp;&amp; small_malloc[i] != NULL; ++i)
      {
          free(small_malloc[i]);
      }
  
      big_malloc = malloc(BIG_MALLOC_SIZE);
      printf("big malloc second time %s\n", (big_malloc == NULL)? "failed" : "succeeded");
      free(big_malloc);
  
      return 0;
  }
  </code></pre>
  
  <p>Here is the result:</p>
  
  <pre><code>big malloc first time succeeded
  small malloc failed at 684912
  big malloc second time failed
  </code></pre>
  
  <p>It looks like there are memory fragments.</p>
  
  <p>I know memory fragmentation happens when there are many small empty space in memory but there is no big enough empty space for big size malloc.</p>
  
  <p>But I've already free <strong>EVERYTHING</strong> I malloc, the memory should be empty.</p>
  
  <p>Why I can't malloc big block at the second time?</p>
  
  <p>I use Visual Studio 2010 on Windows 7, I build 32-bits program.</p>