Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a project's debug instance memory limit

We have a project that is getting an "Out of memory exception". I'm trying to debug this memory leak issue. The problem is that the production machines have about 1-2 GB of memory and the development machines have 6 GB. And I am finding it very difficult to reproduce the crash.

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

like image 497
Tal Even-Tov Avatar asked Nov 04 '22 20:11

Tal Even-Tov


1 Answers

The amount of RAM in a machine has nothing to do with an OutOfMemoryException. You'll get that exception when the process runs out of virtual memory, failing to find a hole in the address space that's big enough to fit an allocation request. That usually happens when the VM size of the process starts getting close to 1.5 GB on a 32-bit machine.

Limiting the amount of virtual memory space is easy enough, just create a bunch of byte[] arrays at the start of your program and store them in a static variable. This doesn't help diagnose a memory leak at all, it merely trips the exception quicker. Use a memory profiler to find the real problem.

And do consider the possibility that this isn't a leak at all, it's not that easy to leak with a garbage collector. But just a side effect of your program processing and storing a lot of data. Which is trivially solved with a 64-bit operating system, it provides oodles of virtual memory space, limited only by the maximum size of the paging file. Not RAM.

like image 151
Hans Passant Avatar answered Nov 08 '22 03:11

Hans Passant