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.
source share