问题
Well, I have to debug a memory allocation issue. The application runs out of memory over time. I need to simulate low memory system for a .net window app, as a way to reproduce the out of memory issue more quickly.
PS: My initial investigation suggests that the memory leak is occurring while the application is allocating unmanaged resources (Managed DX).
回答1:
Write another program that allocates all of your system's memory :)
Alternatively, debug in a VM with low memory
回答2:
static volatile byte[] wasted; //volatile to avoid any compiler cleverness "saving" us!
static void Main(string[] args)
{
wasted = new byte[1024 * 1024 * 1024];//waste a gig!
}
It could also be well worth running the Application Verifier on your app.
回答3:
In addition, I'd suggest you to use a .NET profiler so you can check which area of your program is allocating more memory.
回答4:
If the application is running out of memory accessing unmanaged resources, that is likely to be a memory leak. Running the application in a low-memory environment won't directly help you diagnose the problem, it will just happen faster.
You need to profile the application's memory usage in order to determine how the memory is being allocated and find the leak. Normal profiling tools won't help because the unmanaged code won't be profiled. You'll have to get creative with a memory monitoring app.
来源:https://stackoverflow.com/questions/8466361/how-to-simulate-low-memory-for-net-application