none
Exception: exception of type 'system.outofmemoryexception' was thrown

    Question

  • Hi All,

    I have deployed my website in the production server. Till today it is working fine. But from today I am getting exception message: exception of type 'system.outofmemoryexception' was thrown in my production server. I can only access the site deployed in the production server and don't have access to Production Server and Databaes. How can i fix this problem. It is really urgent for me to fix it today.

    Thanks in advance.
    Thursday, November 20, 2008 8:28 AM

Answers

  •  As this is a prodoction issue, i have to change configuration to avail the unused memory in that server. Here is the way i adopted to solve this issue

    There are some quite definite liimits both to virtual (in 32-bit systems) address space and physical memory.

    To get the most out of what's there in 32-bit environments for ASP.NET, you should do two things:

    1. Enable the /3GB switch in boot.ini.

    2. For IIS 6: In the application pool properties, set the Maximum used memory (in megabytes) to 1800. (Without enabling the /3GB switch, the max value is approx. 800).

    You do not need to have 3Gb or more physical memory to do this. If it's a dedicated web server and this is the only app, 2Gb is sufficient. It'll work with 1Gb as well, but slowly.

    The above will almost get you the 2Gb you want. The next step to increase available memory is to go for an x64 version of the server os.

    • Edited by JNaveen Tuesday, November 25, 2008 1:42 PM spelling mistake
    • Marked as answer by Harry Zhu Wednesday, November 26, 2008 1:33 AM
    Tuesday, November 25, 2008 1:41 PM

All replies

  • Hi!

    Ask this in the ASP.NET Forums: http://forums.asp.net/

    Regards,
    Lucian Baciu, MCTS, http://studentclub.ro/lucians_weblog
    Thursday, November 20, 2008 9:19 AM
  • Thanks for your suggestion.

    But I am expecting the error is being raised from C#.
    My scenario is,

    1. I am invoking a method GetData();
    2. In that method there is a database call and populate a datareader.
    3. Read all ros of the datareader and insert data from the column of type xml into HashTable.
    4. In my case the xml data is around 4MB.

    I am getting System.OutOfMemoryException in the method GetData() (i can not bedug as it is in production server). This method being invoked from multiple places.

    Please let me know whether we have any memory limitations storing data in to HashTable.
    Thursday, November 20, 2008 9:46 AM
  • After observing StackTrace the following are observed.

    1. While Reading data from datareader and assign the data (large >4MB) to HashTable i got the below exception

    Exception of type 'System.OutOfMemoryException' was thrown.:::   at System.String.CreateStringFromEncoding(Byte* bytes, Int32 byteLength, Encoding encoding)
       at System.Text.UnicodeEncoding.GetString(Byte[] bytes, Int32 index, Int32 count)
       at System.Data.SqlClient.TdsParserStateObject.ReadString(Int32 length)
       at System.Data.SqlClient.TdsParser.ReadSqlStringValue(SqlBuffer value, Byte type, Int32 length, Encoding encoding, Boolean isPlp, TdsParserStateObject stateObj)
       at System.Data.SqlClient.TdsParser.ReadSqlValue(SqlBuffer value, SqlMetaDataPriv md, Int32 length, TdsParserStateObject stateObj)
       at System.Data.SqlClient.SqlDataReader.ReadColumnData()
       at System.Data.SqlClient.SqlDataReader.ReadColumn(Int32 i, Boolean setTimeout)
       at System.Data.SqlClient.SqlDataReader.GetValueInternal(Int32 i)
       at System.Data.SqlClient.SqlDataReader.GetValue(Int32 i)
       at Document.ReaderToHashtable(SqlDataReader reader) in E:\Live\Code\Document.cs:line 5457
       at Document.GetDocumentDataSet(Int32 documentID) in E:\Live\Code\Workbench.Storage\Document.cs:line 5426

    For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.



    2. While Loading the data from HashTable to XmlDocument (again same data, large >4MB) i got the below exception

    Exception of type 'System.OutOfMemoryException' was thrown.
       at System.String.GetStringForStringBuilder(String value, Int32 startIndex, Int32 length, Int32 capacity)
       at System.Text.StringBuilder.GetNewString(String currentString, Int32 requiredLength)
       at System.Text.StringBuilder.Append(Char[] value, Int32 startIndex, Int32 charCount)
       at System.IO.StringWriter.Write(Char[] buffer, Int32 index, Int32 count)
       at System.Xml.XmlTextEncoder.WriteStringFragment(String str, Int32 offset, Int32 count, Char[] helperBuffer)
       at System.Xml.XmlTextEncoder.Write(String text)
       at System.Xml.XmlTextWriter.WriteString(String text)
       at System.Xml.XmlText.WriteTo(XmlWriter w)
       at System.Xml.XmlAttribute.WriteContentTo(XmlWriter w)
       at System.Xml.XmlAttribute.WriteTo(XmlWriter w)
       at System.Xml.XmlElement.WriteTo(XmlWriter w)
       at System.Xml.XmlElement.WriteContentTo(XmlWriter w)
       at System.Xml.XmlElement.WriteTo(XmlWriter w)
       at System.Xml.XmlElement.WriteContentTo(XmlWriter w)
       at System.Xml.XmlElement.WriteTo(XmlWriter w)
       at System.Xml.XmlElement.WriteContentTo(XmlWriter w)
       at System.Xml.XmlElement.WriteTo(XmlWriter w)
       at System.Xml.XmlElement.WriteContentTo(XmlWriter w)
       at System.Xml.XmlElement.WriteTo(XmlWriter w)
       at System.Xml.XmlElement.WriteContentTo(XmlWriter w)
       at System.Xml.XmlElement.WriteTo(XmlWriter w)
       at System.Xml.XmlNode.get_OuterXml()
       at UI.InContextTreeView.Page_Load(Object sender, EventArgs e) in e:\Live\Code\UI\InContextTreeView.aspx.cs:line 282

    For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.

    I got this error intermittently at different places for large data. Please throw some thoughts to solve this issue.

    Thanks.

    Friday, November 21, 2008 4:40 AM
  • I doubt you can store such a huge data. Probably you have to review your design and change it to fetch small chunks of data than fetching the whole data.  Could you tell us why you are using a hashtable here?

    Sincerly,
    Navaneeth.K.N
    • Edited by Navaneeth Friday, November 21, 2008 5:20 AM Fixed sig
    Friday, November 21, 2008 5:19 AM
  • Thanks for your reply.

    Actually there is a database call to get list of documents and create a Document object for object of each row in the datareader and assign to HashTable. This code is written in previous version. 

    I accept to resolve this we required to fetch small chunks of data instead of large data at once, but i have to provide some fix for this to solve the current production issue. Is there any work around to increase heap size of the application server?

    As of now i can't apply any code changes in the production, i need some work around to solve this.
    Friday, November 21, 2008 5:26 AM
  • Hi,

    Could you please post the code of GetData()?How did you insert data from the column into hashtable?
    Without it ,we can not reproduce your situation.

    Best regards,
    Harry
    Monday, November 24, 2008 6:59 AM
  •  
    Harry Zhu said:

    How did you insert data from the column into hashtable?



    Just read the value from the datareader and create a custom object and store the object in hashtable. This object contains details of all the data exists in each column of each row in the datareader. As one cloumn of the datareader is very huge (it is xml and size is >4MB) creating object or storing object into hashtable OOM exception is begin raised.
    Tuesday, November 25, 2008 1:38 PM
  •  As this is a prodoction issue, i have to change configuration to avail the unused memory in that server. Here is the way i adopted to solve this issue

    There are some quite definite liimits both to virtual (in 32-bit systems) address space and physical memory.

    To get the most out of what's there in 32-bit environments for ASP.NET, you should do two things:

    1. Enable the /3GB switch in boot.ini.

    2. For IIS 6: In the application pool properties, set the Maximum used memory (in megabytes) to 1800. (Without enabling the /3GB switch, the max value is approx. 800).

    You do not need to have 3Gb or more physical memory to do this. If it's a dedicated web server and this is the only app, 2Gb is sufficient. It'll work with 1Gb as well, but slowly.

    The above will almost get you the 2Gb you want. The next step to increase available memory is to go for an x64 version of the server os.

    • Edited by JNaveen Tuesday, November 25, 2008 1:42 PM spelling mistake
    • Marked as answer by Harry Zhu Wednesday, November 26, 2008 1:33 AM
    Tuesday, November 25, 2008 1:41 PM