Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to simulate low memory for .net application?

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).

like image 816
Trainee4Life Avatar asked Dec 11 '11 18:12

Trainee4Life


People also ask

How do you simulate a memory leak?

You can simulate a memory leak by simply adding objects to a global list on a timer.

How to handle memory leak in. net?

Start the debug diagnostic tool and select 'Memory and handle leak' and click next. Select the process in which you want to detect memory leak. Finally select 'Activate the rule now'. Now let the application run and 'Debugdiag' tool will run at the backend monitoring memory issues.


3 Answers

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.

like image 40
Jon Hanna Avatar answered Sep 28 '22 14:09

Jon Hanna


Write another program that allocates all of your system's memory :)

Alternatively, debug in a VM with low memory

like image 66
Christopher Neylan Avatar answered Sep 28 '22 16:09

Christopher Neylan


In addition, I'd suggest you to use a .NET profiler so you can check which area of your program is allocating more memory.

like image 36
Matías Fidemraizer Avatar answered Sep 28 '22 14:09

Matías Fidemraizer