system.outofmemoryexception was thrown

system.outofmemoryexception was thrown system.outofmemoryexception was thrown

system.outofmemoryexception was thrown occurs when there is not enough memory space for allocation of new objects. Here is a program to reproduce such kind of error using C# program.

using System;
using System.Collections.Generic;
namespace Csharp.Memory.Exception.Example
{
class Program
{
static void Main(string[] args)
{   
List ul = new List(); 
while (true)
{        
UserProfileInformation u = new UserProfileInformation();
u.FirstName = "Satalaj";
ul.Add(u);
}      
}
}
public class UserProfileInformation
{
string _firstName;
public string FirstName
{
get{return _firstName;}
set{_firstName = value;}
}
}
}

How to avoid memory exception errors

To avoid memory exception kind of errors follow below steps.

1. Consider adding sufficient amount of memory [RAM] to machines.

2. If you have more than 2GB memory add 3GB switch in Boot.ini for windows XP operating system.

Upgrade to 64Bit machine, if required.

Asp.net System out of memory exception

Asp.net process model is configure to use reactive process model by default. In this case, if memory consumed by worker process w3wp exceeds 60% of available memory then it throws an memory exception.

You can configure the process model by opening IIS manager and setting application pool to use more than 60% of allowed memory.

Consider adding more physical memory. Don't load more data into Data Table objects or Dataset objects or into Session variables.

Tags:

SystemOutOfMemoryException was thrown (mscorlib)An unhandled exception of type systemstackoverflowexception occurred in mscorlibdllExecuted as user NT AUTHORITY5cSYSTEM A cursor with the name does not exist

Author

My name is Satalaj, but people call me Sat. Here is my homepage: . I live in Pune, PN and work as a Software Engineer. I'm former MVP in ASP.net year 2010.
Disclaimer: Views or opinion expressed here are my personal research and it has nothing to do with my employer. You are free to use the code, ideas/hints in your projects. However, you should not copy and paste my original content to other web sites. Feel free to copy or extend the code.
If you want to fight with me, this website is not for you.
 

I'm Satalaj.