In Windows 8.1, is there a way ensure a process is not the first to get killed when running out of RAM?

I wrote a .NET 4.5 application that buffers colour, infrared, and depth data from a Kinect v2, performs some processing on it, and then dumps it to disk, in uncompressed form; the .NET application also starts ffmpeg as a subprocess and pipes colour data to it to be encoded as H.264.

Because I'm not using an SSD, the video data arrives quicker than I can write to disk. But that's ok, it's acceptable for me to discard video frames when I'm low on RAM. My only requirement is that whatever I keep be mostly contiguous 8- to 10-second chunks of video. So I have added some logic in my .NET 4.5 application to start discarding video frames when I don't have enough RAM to buffer contiguous 8 to 10 seconds of video (roughly 1.5 to 2 GB).

And, to prevent page thrashing, I have completely disabled paging files. This leaves me with a total of 16 GB physical RAM.

My problem is that even with that mechanism in place, sometimes my .NET application or the ffmpeg subprocess still get killed when Windows 8.1 freaks out about low RAM, because obviously my application is using the most RAM when it has a huge backlog of video data to write to disk. Is there a way to tell Windows that my processes are more important than others so that Windows would start killing other less important processes first?


Windows doesn't kill processes when all of the RAM is used. What actually happens is that processes fail to allocate memory and crash.

This is happening because all of your physical memory is in use and because the pagefile is disabled, the memory manager no longer has the ability to write pages that are not being used. This keeps your physical RAM full and when your process, or anything else running at the time, tries to allocate a page, it fails. Some applications crash.

This presentation from Technet explains: http://channel9.msdn.com/Events/TechEd/NorthAmerica/2011/WCL405

The pagefile is keeping applications from crashing when you utilize all of your memory by acting as a backstop for the over commitment.

Virtual memory is pretty much the foundation of how modern operating systems allocate resources, so it's all about having things in RAM that are in use, and moving stuff in and out from disk.

There are really only two answers:

  1. Re-enable the pagefile and increase the RAM on your computer to reduce disk thrashing.
  2. Reduce the memory requirements of your application.

The bottom line is that RAM is just another level of cache, and all of the stuff about virtual memory, pagefiles, memory mapped files, and all that basically comes down to this: if you're running out of memory, you need to add more.