Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

1.2GB memory exception

I read about memory limit

  • Is There Really A 1.2GB Limit For .NET?
  • Is there a memory limit for a single .NET process
  • Memory usage of DotNET app

I have an application which works with huge images which needs to be streamed. Like in a video processing with single frames. The application has about 40 plugins, each of them can contain database, image processing and WPF GUI.

The application also has 2 plugins which uses older DotNet Winforms.

All works well except the application goes over about 1.2GB in RAM. Then on unusual locations in the plugins where new memory is allocated I receive the "Out of Memory exception".

I am working on a 64Bit system compiled as 32Bit. I have no more idea what to do and how to search for any fault.

Is there a limit or can I catch them?

like image 483
Nasenbaer Avatar asked Jun 06 '12 17:06

Nasenbaer


People also ask

How do I fix out of memory exception in C #?

You can do either of the following to address the error: Replace the call to the StringBuilder. StringBuilder(Int32, Int32) constructor with a call any other StringBuilder constructor overload. The maximum capacity of your StringBuilder object will be set to its default value, which is Int32.

What is system out of memory exception?

If Windows cannot find a contiguous block of memory large enough to satisfy the request and make it fit within the 2GB address space for the application, i.e. fit along with all the other memory the application is already using, you will get an OutOfMemoryException error from the OS and the application usually will be ...

How do you increase the memory limit for 32 bit applications in Windows 64 bit OS?

One of the simplest ways to increase the amount of memory a process can use on 32-bit Windows is to enable the /3GB flag in the Windows' boot. ini file. This has the effect of adjusting the kernel/user address space split in favour of the application by 1GB, i.e. instead of a 2GB/2GB split you have a 3GB/1GB split.


1 Answers

It is very difficult to write a 32-bit program that consumes all of the available virtual memory space. You'll hit the wall well below 2 gigabytes, what you run out of first is a chunk of virtual memory that's large enough to fit the requested size. You can only get up to the 2GB limit by making small allocations, small enough to fit in the holes.

That wall hits early in a program that manipulates bitmaps. They can consume a big chunk of VM to store the bitmap pixels and it needs to be a contiguous allocation. They are stored in an array, not a tree. It's an unmanaged memory allocation, typical .NET memory profilers tend to be a bit helpless to show you the problem.

There isn't anything reasonable you can do about address space fragmentation, the notion that consuming all available VM should be possible is just wrong. You can get more breathing space on a 64-bit operating system by running editbin.exe in a post build event and use its /LARGEADDRESSAWARE command line option. That allows the process to use the available 4 gigabytes of VM, an option that's specific to the 64-bit version of Windows and possible because Windows doesn't need the upper 2GB. And of course, changing the platform target to AnyCPU is a quick and easy way to get gobs of virtual memory.

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

Hans Passant