83
Views
1
Comments
OutOfMemory when parsing large xml files
Question
I'm having the following problem:

Before i wnat to load an XMLDocument with XmlDocument_Load, it's nessesary to first change it from BinaryData to Text with BinaryData.BinaryDataToText.

This causes an OutOfMemoryExeption, anyone has a sollution for this?

Message:

[1] Exception of type 'System.OutOfMemoryException' was thrown.

Stack:

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.StreamReader.ReadToEnd()
at OutSystems.NssBinaryData.CssBinaryData.MssBinaryDataToText(Byte[] ssBinaryData, String ssEncoding, String& ssText)
at ssDigiDo.RssExtensionBinaryData.MssBinaryDataToText(HeContext heContext, Byte[] inParamBinaryData, String inParamEncoding, String& outParamText)
at ssDigiDo.Flows.FlowTest.ScrnMain.CommandLoad_XML_Document(HeContext heContext)
at ssDigiDo.Flows.FlowTest.ScrnMain.wt_Submitwidget426278_Click(Object sender, EventArgs e)
at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
2024-12-17 14-32-59
Matthias Preuter
 
MVP
Found a solution, changed the code below, and changed the IIS settings to OutSystems recommended settings:

OutSystems recommends the following limits for worker process memory, in 32-bit Operating Systems:
Physical memory: 800Mb or 60% of the physical RAM in the server (whichever is bigger);
Virtual memory: 1400Mb.
<codesnippet>
public void MssBinaryDataToText ( byte[] ssBinaryData, string ssEncoding, out string ssText) {

System.Text.Encoding encoding = ssEncoding == String.Empty ? System.Text.Encoding.Default : System.Text.Encoding.GetEncoding (ssEncoding);

ssText = encoding.GetString(ssBinaryData);
GC.Collect();
/*
MemoryStream stream = new MemoryStream (ssBinaryData);
StreamReader reader = new StreamReader (stream, encoding);
ssText = reader.ReadToEnd ();
reader.Close (); stream.Close(); */ }
</codesnippet>
Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.