Wednesday, July 09, 2008

Memory is a stranger

Carrying on a series of posts in which I try to fix a problem before it drives me mad...

More DibGraphics crashes. The current thinking has it that when we run out of memory, then attempt a memory-intensive operation such as a double-buffered paint, we crash.

This one is totally reproducible.

Step 1: Turn off your pagefile. Set this to "No paging file".

Step 2: Eat memory like a fat man at an all-you-can-eat buffet.

Step 3: Paint a double-buffered dialog.

And bang! You get a crash. Probably a System.ComponentModel.Win32Exception, either "The operation completed successfully" or "Not enough storage is available to process this command".

Obviously there are two ways around this. Don't run out of memory, or don't double buffer. Although, if you're out of memory you're gonna go down hard at some point, whether it's the double buffer that kills you or something else. The question I have is, can we fail more gracefully?


  1. Anonymous11:17 am

    To crash gracefully can you not check the number of GDI objects you are using and if you get above a threshold (maybe 90% of max) then shit the bed, nicely?

  2. On every paint? I guess so, but if you're really out of memory, you're going to crash, no matter what.