How to set the memory limit of a project instance

We have a project that gets an "Out of memory" exception. I am trying to debug this memory leak problem. The problem is that production machines have about 1-2 GB of memory, and development machines have 6 GB. And it’s very difficult for me to reproduce the collapse.

Is there a way in visual studio that I can reduce the amount of memory that can be allocated for a debug instance?

+4
source share
1 answer

The amount of RAM in the machine has nothing to do with OutOfMemoryException. You will get this exception when the process ends from virtual memory without finding a hole in the address space that is large enough to match the distribution request. This usually happens when the size of the virtual machine in the process begins to approach 1.5 GB on a 32-bit machine.

Limiting the amount of virtual memory is quite simple, just create an array of bytes [] at the beginning of your program and save them in a static variable. This does not help diagnose a memory leak at all, but simply speeds up the exception. Use the memory profiler to find the real problem.

And think that this is not a leak at all, it is not so easy to seep with the garbage collector. But just a side effect of your program processing and storing large amounts of data. Which is trivially solved using a 64-bit operating system, it provides a lot of virtual memory, limited only by the maximum size of the page file. Not RAM.

+2
source

All Articles