Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I simulate a low memory condition in Windows 7

I have an application written in C# that works well, but occasionally in the field gives errors which we believe are due to low memory conditions, or interactions with the garbage collector.

If anyone is interested, it is described here:
Unable to cast object of type 'NHibernate.Impl.ExpandedQueryExpression' to type 'NHibernate.Linq.NhLinqExpression'

I want to try and reproduce this for debugging, but my development machine has too much memory.

I've removed the pagefile so my virtual memory is limited to the 12GBs of physical memory so aside from physically removing ram, does anyone have any suggestions on how to simulate a low memory condition in a development environment?

EDIT:
Removed asking about tools which monitor the garbage collector?

like image 326
Noah Avatar asked Oct 19 '11 20:10

Noah


2 Answers

You could use a Virtual Machine (VPC, VMWare or Virtual Box) and tune the memory down.

That is more reliable than a bug.

EDIT

This suggestion is a way of simulating a PC with less physical memory. As stated in comments and in other answers, if you are looking to tune down virtual memory 'eating away' the heap at the start of the process would be a solution.

like image 93
Emond Avatar answered Oct 14 '22 04:10

Emond


The amount of RAM you have is not relevant on a virtual memory operating system like Windows. Not having enough only slows down the program. What matters is the size of the virtual memory address space, 2 gigabytes on a 32-bit operating system. Set the target platform on your EXE project to x86 if you have a 64-bit operating system.

You can arbitrary increase memory pressure by calling Marshal.AllocHGlobal() at the start of your program. Allocate a chunk of, say, 500 megabytes. Not more, that will fail easily. Grab more by allocating 90 MB chunks.

like image 26
Hans Passant Avatar answered Oct 14 '22 04:10

Hans Passant