Click here to Skip to main content
12,395,319 members (66,512 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# ASP.NET
In My Project When I Compiled "System.out of memory Exception" is Always Throwing.
In My System It Is 2gb RAM and 160GB hard disk. In c drive available space is there.
Is it the hard ware problem or my project Problem.
Please answer it.
Posted 6-Nov-11 22:12pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

In a normal 32 bit windows app, the process only has 2GB of addressable memory. This is irrelevant to the amount of physical memory that is available.

So 2GB available but 1.5 is the max you can allocate. The key is that your code is not the only code running in the process. The other .5 GB is probably the CLR plus fragmentation in the process.
Rate this: bad
Please Sign up or sign in to vote.

Solution 4

Your RAM and HDD space are not playing big role in your above excpetion.
Make the code worthy that deal with proper memory managment.

check following points in your code to avoid memory leaks

1. Close your connection after you have used it.
2. Close all Datareaders after you have used
3. Make NULL all dataset after used.
4. dispose your all object.

May be your darareaders are open in your project.

Change your code and check the effect.
Rate this: bad
Please Sign up or sign in to vote.

Solution 5

Not sure about your code. Did you dispose the things properly?

Check these

IDisposable.Dispose Method[^]
using Statement (C# Reference)[^]
The "using" Keyword in C#[^]
Dispose and Finalize with C++/CLI, C# and VB[^]
When and How to Use Dispose and Finalize in C#[^]

And a sample thread found in SO which contains similar issue so that would be useful for you.
Out Of Memory exception on System.Drawing.Image.FromFile()[^]
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Try this[^]
Oops, my bad. I thought you cannot use more than 2 GB. Still you can check your code and make it more memory efficient so that it works smoothly.
Rate this: bad
Please Sign up or sign in to vote.

Solution 6

Check that you are building a 64-bit process, and not a 32-bit one, which is the default compilation mode of Visual Studio. To do this, right click on your project, Properties -> Build -> platform target : x64. As any 32-bit process, Visual Studio applications compiled in 32-bit have a virtual memory limit of 2GB.

Each process has its own virtual memory, called an address space, into which it maps the code that it executes and the data it manipulates. A 32-bit process uses 32-bit virtual memory address pointers, which creates an absolute upper limit of 4GB (2^32) for the amount of virtual memory that a 32-bit process can address. However, the operating system requires half of it (to reference its own code and data), creating a limit of 2GB for each process. If your 32-bit application tries to consume more than the entire 2GB of its address space, it will return “System.OutOfMemory”, even though the physical memory of your computer is not full.

64-bit processes do not have this limitation, as they use 64-bit pointers, so their theoretical maximum address space is 16 exabytes (2^64). In reality, Windows x64 limits the virtual memory of processes to 8TB. The solution to the memory limit problem is then to compile in 64-bit.

However, object’s size in Visual Studio is still limited to 2GB, by default. You will be able to create several arrays whose combined size will be greater than 2GB, but you cannot by default create arrays bigger than 2GB. Hopefully, if you still want to create arrays bigger than 2GB, you can do it by adding the following code to you app.config file:

<gcAllowVeryLargeObjects enabled="true" />
Ron Beyer 26-Jun-13 10:33am
Why are you resurrecting a 2 and a half year old question? 30-Oct-15 13:05pm
***More information*** 3.5 vs 4.0

My case about ***OutOfMemoryException*** is not memory problem,

I don't know yet

_Maybe configuration IIS, Pool, web.config issues ?_
Rate this: bad
Please Sign up or sign in to vote.

Solution 3


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 22 May 2015
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100