Out of memory exception analysing some code
Hi,
I keep getting out of memory exceptions due to the following code. (And I
submitted a couple of them) The example code does not compile because of
missing other classes, but my gui gets really slow even without the extra
methods and classes.
Removing the line "using System.Xml" seems to solve the problem.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
namespace ConsoleApplication1
{
public class XmlUtil
{}
class Program
{
static void Main(string[] args)
{
XmlDocument theXmlDoc = new XmlDocument();
XmlUtil theXmlUtils = new XmlUtil(theXmlDoc);
// Namespace.DataTTTRegeling moet zijn
NameSpace.TTTThing.Algemeen.DataTTTRegeling
XmlNodeList theNodeList =
theXmlDoc.SelectNodes("//*");
foreach (XmlNode theNode in theNodeList) {
foreach (XmlAttribute attr in theNode.Attributes)
if (attr.Name == "type")
attr.Value = "NameSpace.TTTThing.Algemeen.DataTTTRegeling";
XmlNode theChildNode = theXmlUtils.GetElement(0, "Fondsen_x0020_mix",
null, theNode);
theNode.RemoveChild(theChildNode);
if (theChildNode != null)
theChildNode.Attributes.Append(theXmlDoc.CreateAttribute("type")).Value
= "NameSpace.Dno.DataFondsMix";
}
// Namespace.DataTTTAanspraakGegevens moet zijn
NameSpace.TTTThing.Algemeen.DataTTTAanspraakgegevens
theNodeList =
theXmlDoc.SelectNodes("//*");
foreach (XmlNode theNode in theNodeList) {
foreach (XmlAttribute attr in theNode.Attributes)
if (attr.Name == "type")
attr.Value = "NameSpace.TTTThing.Algemeen.DataTTTAanspraakgegevens";
}
theNodeList =
theXmlDoc.SelectNodes("//*");
foreach (XmlNode theNode in theNodeList) {
foreach (XmlAttribute attr in theNode.Attributes)
if (attr.Name == "type")
attr.Value = "NameSpace.Thing.DataAdministratieDeelnemer";
}
theNodeList =
theXmlDoc.SelectNodes("//*");
foreach (XmlNode theNode in theNodeList) {
foreach (XmlAttribute attr in theNode.Attributes)
if (attr.Name == "type")
attr.Value = "NameSpace.Thing.DataAdministratieAlgemeneDeelnemer";
theXmlUtils.RemoveElement(0, "Te_x0020_bereiken_x0020_inhaalThing",
null, theNode);
}
// Namespace.DataTTTAanspraakVastSalaris moet zijn
NameSpace.TTTThing.Algemeen.DataTTTAanspraakVastSalaris
theNodeList =
theXmlDoc.SelectNodes("//*");
foreach (XmlNode theNode in theNodeList) {
foreach (XmlAttribute attr in theNode.Attributes)
if (attr.Name == "type")
attr.Value =
"NameSpace.TTTThing.Algemeen.DataTTTAanspraakVastSalaris";
}
// Namespace.DataTTTAlgemeneRegeling moet zijn
NameSpace.TTTThing.Algemeen.DataTTTAlgemeneRegeling
theNodeList =
theXmlDoc.SelectNodes("//*");
foreach (XmlNode theNode in theNodeList) {
foreach (XmlAttribute attr in theNode.Attributes)
if (attr.Name == "type")
attr.Value = "NameSpace.TTTThing.Algemeen.DataTTTAlgemeneRegeling";
XmlNode theFranchiseNode = theXmlDoc.CreateNode(XmlNodeType.Element,
null, "Franchise", null);
theFranchiseNode.Attributes.Append(theXmlDoc.CreateAttribute("type")).Value
= "NameSpace.Thing.DataFranchise";
XmlNode theChildNode = theXmlUtils.GetElement(0,
"Soort_x0020_franchise", null, theNode);
theNode.RemoveChild(theChildNode);
string theValue = theChildNode.InnerText;
theChildNode.InnerText = theValue == "AOWGehuwd" ? "AOW_Gehuwd_x1" :
theValue == "AOWGehuwd2x" ? "AOW_Gehuwd_x2" : theValue;
theFranchiseNode.AppendChild(theChildNode);
XmlNode theFranchiseAnderAanvangsBedragNode =
theXmlDoc.CreateNode(XmlNodeType.Element, null,
"Ander_x0020_aanvangsbedrag", null);
theFranchiseAnderAanvangsBedragNode.Attributes.Append(theXmlDoc.CreateAttribute("type")).Value
= "NameSpace.Thing.DataAanvangsbedrag";
theChildNode = theXmlUtils.GetElement(0,
"Franchisebedrag_x0020_bij_x0020_aanvang", null, theNode);
theNode.RemoveChild(theChildNode);
theFranchiseAnderAanvangsBedragNode.AppendChild(theChildNode);
theChildNode = theXmlUtils.GetElement(0,
"Toelichting_x0020_franchise", null, theNode);
theNode.RemoveChild(theChildNode);
theFranchiseAnderAanvangsBedragNode.AppendChild(theChildNode);
theNode.AppendChild(theFranchiseNode);
theFranchiseNode.AppendChild(theFranchiseAnderAanvangsBedragNode);
}
// XPath expression; Search and replace type-names
// Remove Interest percentage and replace it by the
DataStaffelGeneratieInfo
theNodeList =
theXmlDoc.SelectNodes("//*");
foreach (XmlNode theXmlNode in theNodeList) {
theXmlUtils.RemoveElement(0, "Interest", null, theXmlNode);
theXmlNode.AppendChild(theXmlDoc.CreateNode(XmlNodeType.Element,
null, "Staffel_x0020_Generator", null));
}
// Begin Salaris Conversie
foreach (XmlNode theXmlNode in
theXmlDoc.SelectNodes("//*"))
if (theXmlNode.Name == "Algemene_x0020_regeling") {
string theSalarisOmschrijving = "Jaarsalaris incl. vakantiegeld";
string theSalarisOpbouwOmschrijving = (string)
theXmlUtils.GetValueFromElement(0, "Salaris_x0020_opbouw", null, typeof
(string), theXmlNode);
bool theDertiendeMaand = false;
EPeriode theSalarisPeriode = EPeriode.Jaar;
if (theSalarisOpbouwOmschrijving.StartsWith("12,96")) {
theSalarisPeriode = EPeriode.Maand;
theDertiendeMaand = false;
} else if (theSalarisOpbouwOmschrijving.StartsWith("13,96")) {
theSalarisPeriode = EPeriode.Maand;
theDertiendeMaand = true;
} else if (theSalarisOpbouwOmschrijving.StartsWith("14,04")) {
theSalarisPeriode = EPeriode.VierWeken;
theDertiendeMaand = false;
}
theSalarisOmschrijving = theSalarisOpbouwOmschrijving;
theXmlUtils.RemoveElement(0, "Salaris_x0020_opbouw", null,
theXmlNode);
XmlNode theNewBVSNode = theXmlDoc.CreateNode(XmlNodeType.Element,
null, "Bestandsdelen_x0020_Vast_x0020_Salaris", null);
theNewBVSNode.Attributes.Append(theXmlDoc.CreateAttribute("type")).Value
= "NameSpace.Thing.DataBestandsdelenVastSalaris";
XmlNode theNewXmlNode = theXmlDoc.CreateNode(XmlNodeType.Element,
null, "Vakantie_x0020_Geld", null);
theNewXmlNode.InnerText = "True";
theNewBVSNode.AppendChild(theNewXmlNode);
theNewXmlNode = theXmlDoc.CreateNode(XmlNodeType.Element, null,
"Vast_x0020_Salaris_x0020_Per", null);
theNewXmlNode.InnerText = theSalarisPeriode.ToString();
theNewBVSNode.AppendChild(theNewXmlNode);
theNewXmlNode = theXmlDoc.CreateNode(XmlNodeType.Element, null,
"Dertiende_x0020_Maanden", null);
theNewXmlNode.InnerText = theDertiendeMaand ? "True" : "False";
theNewBVSNode.AppendChild(theNewXmlNode);
theNewXmlNode = theXmlDoc.CreateNode(XmlNodeType.Element, null,
"Overige_x0020_Inkomsten", null);
theNewXmlNode.InnerText = "False";
theNewBVSNode.AppendChild(theNewXmlNode);
theNewXmlNode = theXmlDoc.CreateNode(XmlNodeType.Element, null,
"Overige_x0020_Inkomsten_x0020_Per", null);
theNewXmlNode.InnerText = "Jaar";
theNewBVSNode.AppendChild(theNewXmlNode);
theNewXmlNode = theXmlDoc.CreateNode(XmlNodeType.Element, null,
"Omschrijving", null);
theNewXmlNode.InnerText = theSalarisOmschrijving;
theNewBVSNode.AppendChild(theNewXmlNode);
theXmlNode.ParentNode.AppendChild(theNewBVSNode);
}
foreach (XmlNode theXmlNode in
theXmlDoc.SelectNodes("//*"))
if (theXmlNode.Name == "Periodieke_x0020_gegevens") {
double theJaarSalaris = (double) theXmlUtils.GetValueFromElement(0,
"Vast_x0020__x0028_parttime_x0029__x0020_salaris", null, typeof (double),
theXmlNode);
theXmlUtils.RemoveElement(0,
"Vast_x0020__x0028_parttime_x0029__x0020_salaris", null, theXmlNode);
string theRegelingID = (string) theXmlUtils.GetValueFromElement(0,
"Regeling_x0020_ID", null, typeof (string), theXmlNode.ParentNode);
XmlNode theRegelingBVSNode = null;
foreach (XmlNode theBVSNode in
theXmlDoc.SelectNodes("//*"))
if (theRegelingID == (string) theXmlUtils.GetValueFromElement(0,
"StoredObjectID", null, typeof (string),
theBVSNode.ParentNode.ParentNode)) {
theRegelingBVSNode = theBVSNode;
break;
}
if (theRegelingBVSNode == null)
throw new NullReferenceException("Conversie: Er is geen regeling
met ID = " + theRegelingID);
EPeriode theVastSalarisPer = (EPeriode)
theXmlUtils.GetValueFromElement(0, "Vast_x0020_Salaris_x0020_Per", null,
typeof (EPeriode), theRegelingBVSNode);
bool theDertiendeMaand = (bool) theXmlUtils.GetValueFromElement(0,
"Dertiende_x0020_Maanden", null, typeof (bool), theRegelingBVSNode);
double theDeelFactor = 0;
if (theVastSalarisPer == EPeriode.Maand) {
if (theDertiendeMaand) {
theDeelFactor = 13.96;
} else {
theDeelFactor = 12.96;
}
} else if (theVastSalarisPer == EPeriode.VierWeken &&
!theDertiendeMaand) {
theDeelFactor = 14.04;
} else if (theVastSalarisPer == EPeriode.Jaar && !theDertiendeMaand)
{
theDeelFactor = 1.08;
}
XmlNode theNewSGNode = theXmlDoc.CreateNode(XmlNodeType.Element,
null, "Vast_x0020__x0028_parttime_x0029__x0020_salaris", null);
theNewSGNode.Attributes.Append(theXmlDoc.CreateAttribute("type")).Value
= "NameSpace.Thing.DataSalarisGegevens";
XmlNode theNewXmlNode = theXmlDoc.CreateNode(XmlNodeType.Element,
null, "Vast_x0020_Salaris_x0020_Per_x0020_Periode", null);
theNewXmlNode.InnerText = (theJaarSalaris /
theDeelFactor).ToString();
theNewSGNode.AppendChild(theNewXmlNode);
theNewXmlNode = theXmlDoc.CreateNode(XmlNodeType.Element, null,
"Dertiende_x0020_Maanden", null);
theNewXmlNode.InnerText = theDertiendeMaand ? (theJaarSalaris /
theDeelFactor).ToString() : "0";
theNewSGNode.AppendChild(theNewXmlNode);
theNewXmlNode = theXmlDoc.CreateNode(XmlNodeType.Element, null,
"Overige_x0020_Inkomsten_x0020_Per_x0020_Periode", null);
theNewXmlNode.InnerText = "0";
theNewSGNode.AppendChild(theNewXmlNode);
theXmlNode.AppendChild(theNewSGNode);
}
// Einde Salaris Conversie
}
}
}
Please sign in to leave a comment.
Hello Arnold,
Thank you for providing a full sample! I've created a bug-report at http://youtrack.jetbrains.net/issue/RSRP-263381
and you're welcome to monitor its status.
Andrey Serebryansky
Senior Support Engineer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"