title: How to keep track of how much memory is leaked?
body: <p>I'm working on a homework assignment that requires me to write a program that leaks memory, keep track of how much memory it is leaking until it crashes. </p>
  
  <p>My general thoughts for the program would be to continuously reassign a malloc pointer.</p>
  
  <p>Here's my code so far:</p>
  
  <pre><code>char *oldMemory = malloc(125000); //1MB of memory.
  char *newMemory = malloc(125000);
  oldMemory = newMemory;
  </code></pre>
  
  <ul>
  <li>Is there are way to put this in a loop and repeatedly orphan a
  certain amount of memory until the program can no longer allocate any memory and     crashes?</li>
  <li>How can I keep track of how much memory was leaked before the program crashed? </li>
  </ul>
  
  <p>Thanks for your time and expertise!</p>