title: How can I get a guarantee that when a memory is freed, the OS will reclaim that memory for it's use?
body: <p>I noticed that this program:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main() {
    const size_t alloc_size = 1*1024*1024;
    for (size_t i = 0; i &lt; 3; i++) {
      printf("1\n");
      usleep(1000*1000);
      void *p[3];
      for (size_t j = 3; j--; )
        memset(p[j] = malloc(alloc_size),0,alloc_size); // memset for de-virtualize the memory
      usleep(1000*1000);
      printf("2\n");
      free(p[i]);
      p[i] = NULL;
      usleep(1000*1000*4);
      printf("3\n");
      for (size_t j = 3; j--; )
        free(p[j]);
    }
  }
  </code></pre>
  
  <p>which allocates 3 memories, 3 times and each time frees different memory, frees the memory according to <code>watch free -m</code>, which means that the OS reclaimed the memory for every <code>free</code> regardless of the memory's position inside the program's address space. Can I somehow get a guarantee for this effect? Or is there already anything like that (like a rule of <code>&gt;64KB</code> allocations)?</p>