How to simulate low memory status in Windows 7

I have an application written in C # that works well, but sometimes errors appear in the field, which, in our opinion, are caused by low memory conditions or interaction with the garbage collector.

If anyone is interested, this is described here:
Unable to pass object of type "NHibernate.Impl.ExpandedQueryExpression" to enter "NHibernate.Linq.NhLinqExpression"

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

I deleted the swap file so that my virtual memory is limited to 12 GB of physical memory, so besides physically deleting the bar, are there any suggestions on how to simulate the low memory state in the development environment?

EDIT:
Resolved a question about tools that track the garbage collector?

+7
source share
9 answers

You can use a virtual machine (VPC, VMWare or Virtual Box) and configure the memory down.

This is more reliable than error.

EDIT

This proposal is a way to simulate a PC with less physical memory. As stated in the comments and other answers, if you want to configure the removal of "virtual memory", the heap at the beginning of the process will be the solution.

+5
source

The amount of RAM that you have is not related to a virtual memory operating system such as Windows. It is not enough to slow down the program. The size of the address space of virtual memory matters, 2 gigabytes in a 32-bit operating system. Install the target platform in an x86 EXE project if you have a 64-bit operating system.

You can arbitrarily increase memory pressure by calling Marshal.AllocHGlobal () at the beginning of your program. Select a piece of, say, 500 megabytes. No more, it will fail easily. Grab more by allocating 90 MB chunks.

+3
source

Not an answer, but a very cool utility that I found in Code Project - a memory allocation tool

Introduction

Sometimes it is very useful to test your applications in extreme situations, for example, low resources, a full hard disk or low memory conditions.

This tool covers only the last - memory.
It allows you to allocate as much memory as can be available.

Memory allocation tool

+3
source

You can use Windows performance counters to track the activity of your garbage collector and the memory usage of your processes.

To fill your RAM, you should not allocate a rather large array from a C # program?

0
source

You can use a simple C program to allocate or try to allocate arbitrary amounts of memory on the heap:

#include <stdio.h> #include <stdlib.h> #define MB (1024*1024) #define DEFAULT_ALLOC ((size_t) (512*MB)); int main(int argc, char *argv[]) { char buffer[2]; char *chunk; char *endp; size_t howmuch; if ( argc < 2 ) { howmuch = DEFAULT_ALLOC; } else { howmuch = strtoul(argv[1], &endp, 10); if ( *endp ) { fputs("Failed to parse command line argument", stderr); howmuch = DEFAULT_ALLOC; } else { howmuch *= MB; } } chunk = calloc(howmuch, 1); if ( chunk == NULL ) { fputs("Memory allocation error", stderr); exit(EXIT_FAILURE); } puts("Memory allocated.\nPress ENTER to terminate program"); fgets(buffer, 2, stdin); return EXIT_SUCCESS; } 
0
source

This is a very simple program that we use to test low memory conditions on our Linux servers. I never compiled it on windows, but it should work.

https://github.com/julman99/eatmemory

Hope this works for you.

0
source

Found this utility, which is now FreeWare: http://www.soft.tahionic.com/download-memalloc/

0
source

All Articles