Hi @Harshithraj1871 ,
Is it possible to simulate an OOM condition by exhausting kernel memory (e.g., USER/GDI or non-paged pool) from a user-mode Win32 application?
It's possible but I strongly advise against this approach. Exhausting kernel resources like the non-paged pool can destabilize or crash the entire system, not just your application. Windows has built-in protections, but pushing these limits is risky.
If not, what is the correct or industry-standard approach to testing OOM handling in Win32 desktop applications?
Consider these industry-standard practices:
- Use Windows Application Verifier with Low Resource Simulation - this tool can simulate memory allocation failures without actually exhausting memory
- Implement fault injection in your code using preprocessor directives or a test mode that makes allocations fail after certain thresholds
- Use memory limit tools like Job Objects (
SetProcessMemoryLimit) to constrain your process to a specific memory budget - Virtual machine testing - run your app in a VM with very limited RAM (e.g., 512MB) to naturally trigger memory pressure
You've correctly identified that USER/GDI subsystems use kernel memory. This is actually by design - Windows tries to keep critical UI functions alive even under memory pressure so users can at least see error dialogs and potentially save work.
It's better to focus on testing your application's own allocation failures rather than trying to exhaust all system memory. Most real-world OOM scenarios in production will fail your app's allocations while the system remains functional.