title: What to do when an out-of-memory error occurs?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/3596990/whats-the-graceful-way-of-handling-out-of-memory-situations-in-c-c">What&#39;s the graceful way of handling out of memory situations in C/C++?</a>  </p>
  </blockquote>
  
  
  
  <p>Hi,</p>
  
  <p>this seems to be a simple question a first glance. And I don't want to start a huge discussion on what-is-the-best-way-to-do-this....  </p>
  
  <p>Context: Windows >= 5, 32 bit, C++, Windows SDK / Win32 API</p>
  
  <p>But after asking a <a href="https://stackoverflow.com/questions/3533429/c-windows-how-to-report-an-out-of-memory-exception-bad-alloc">similar question</a>, I read some MSDN and about the Win32 memory management, so now I'm even more confused on what to do if an allocation fails, let's say the C++ new operator.  </p>
  
  <p>So I'm very interested now in how <strong>you</strong> implement (and implicitly, if you do implement) an error handling for OOM in your applications.<br>
  <strong>If, where</strong> (main function?)<strong>, for which operations</strong> (allocations) <strong>, and how you handle an OOM error.</strong></p>
  
  <p>(I don't really mean that subjectively, turning this into a question of preference, I just like to see different approaches that account for different conditions or fit different situations. So feel free to offer answers for GUI apps, services - user-mode stuff ....)</p>
  
  <p>Some exemplary reactions to OOM to show what I mean:</p>
  
  <ul>
  <li>GUI app: Message box, exit process</li>
  <li>non-GUI app: Log error, exit process</li>
  <li>service: try to recover, e.g. kill the thread that raised an exception, but continue execution</li>
  <li>critical app: try again until an allocation succeeds (reducing the requested amount of memory)</li>
  <li>hands from OOM, let STL / boost / OS handle it</li>
  </ul>
  
  <p>Thank you for your answers!  </p>
  
  <p>The best-explained way will receive the great honour of being an <em>accepted answer</em> :D - even if it only consists of a MessageBox line, but explains why evering else was useless, wrong or unneccessary.
  <br />
  <br />
  Edit: I appreciate your answers so far, but I'm missing a bit of an actual <em>answer</em>; what I mean is most of you say don't mind OOM since you can't do anything when there's no memory left (system hangs / poor performance). But does that mean to avoid any error handling for OOM? Or only do a simple try-catch in the main showing a MessageBox?</p>