Domanda

Dim docu As New XmlDocument()
docu.load("C:\bigfile.xml")

Dim tempNode As XmlNode
tempNode = docu.SelectSingleNode("/header/type")

someArray(someIndex) = tempNode.innerText

...do something more...

I am using XmlDocument() to load a huge XML document (100~300MB)

When I open the document and read it as string, my application uses about 900MB of RAM. I wonder why it happens and how can I prevent it ?

Note that : even, the XmlDocument does not have Dispose() to remove allocated things. Although I need the whole string of the huge XML file in later part of the app, the /header/type.innerText is only a single word


More of source :

Private Sub setInfo(ByVal notePath As String)

        Dim _NOTE As XDocument

        _NOTE = XDocument.Load(notePath)

        If (From node In _NOTE...<title> Select node).Value = "" Then
            lvlist.Items.Add("No Title")
        Else
            lvlist.Items.Add((From node In _NOTE...<title> Select node).Value)
        End If

        lvlist.Items(lvlist.Items.Count - 1).SubItems.Add((From node In _NOTE...<group> Select node).Count)


End Sub

It reads XML document, counts tags and retrieves string value. That's all. After having those values, _NOTE (XDocument) is of no use at that time.

È stato utile?

Soluzione

XmlReader will probably solve your need. From MSDN:

Represents a reader that provides fast, noncached, forward-only access to XML data.

Altri suggerimenti

Right, XmlDocument does not have a Dispose method. It is put into memory. It does follow an object life cycle. So if you create the object in a Function and return the string you want then it will free itself as it losses scope from the Function.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top