title: How to avoid the "swapping of death" during development?
body: <p>Probably everyone ran into this problem at least once during development:</p>
  
  <pre><code>while(/*some condition here that somehow never will be false*/)
  {
      ...
      yourvector.push_back(new SomeType());
      ...
  }
  </code></pre>
  
  <p>As you see the program starts to drain all system memory, your program hangs and your system starts to swap like crazy. If you don't recognize the problem fast enough and kill the process you probably get an unresponsive system in seconds where your mouse pointer don't even moving. You can either wait your program crash with "out of memory" error (which may take several long minutes) or hit the reset on your computer.</p>
  
  <p>If you can't track down the bug immediately then you will need several tests and resets to find out which is very annoying...</p>
  
  <p>I'm looking for a possibly cross-platform way to prevent this somehow. The best would be a debug mode code that exits the program if it allocated too much memory, but how can I keep track how much memory is allocated?
  Overriding the global new and delete operators won't help, because the free function I would invoke in the delete won't give any idea how many bytes are freed.</p>
  
  <p>Any ideas appreciated.</p>