none
Unloading an XmlDocument RRS feed

  • Question

  • Hi All,

    I just wanted to understand why this big xml document is not unloading from memory? And is there a way to unload this document from memory? size of document is 400MB or so.

    public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void simpleButton1_Click(object sender, EventArgs e)
            {
                string fName = "C:\\TestData.xml";
                XmlDocument xDoc = LoadFromXml(fName);
                int gen = GC.GetGeneration(xDoc);
                xDoc = null;
                GC.Collect(0, GCCollectionMode.Forced);
                GC.Collect(1, GCCollectionMode.Forced);
                GC.Collect(2, GCCollectionMode.Forced);
            }
            public XmlDocument LoadFromXml(string fileName)
            {
    #if DEBUG
                Stopwatch stp = new Stopwatch();
                stp.Start();
    #endif
                XmlDocument xmlFile = new XmlDocument();
    
                if (File.Exists(fileName))
                {
                    //TBD: unload an xmldocument
                    xmlFile.Load(fileName);
                }
                else
                    throw new FileNotFoundException("Xml File Not Found", fileName);
    #if DEBUG
                stp.Stop();
                Debug.Write(stp.Elapsed.Seconds.ToString());
    #endif
                return xmlFile;
            }
    
        }
    

     

    Thanks,

    Paraclete

    Monday, October 3, 2011 1:59 AM

Answers

All replies