How to simulate low memory for .net application?

别来无恙 提交于 2019-12-10 16:46:02

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!