[Mono-dev] XmlDocument.ReadNode() causes huge memory consumpsion by XmlTextReader

Sasha Kogan sashak at mainsoft.com
Mon Nov 3 09:47:20 EST 2008


Hi,
I get OutOfMemoryError (I use Grasshopper, but the problem is not
Java-specific) when running the following code:

void runTest(string filename)
{
    XmlDocument doc = new XmlDocument();
    XmlReader xmlReader = XmlReader.Create(filename);

    while (!xmlReader.EOF)
    {
	if ((xmlReader.NodeType == XmlNodeType.Element) &&
(xmlReader.Depth == 1))
	    doc.ReadNode(xmlReader);
	else
	    xmlReader.Read();
    }
}

on a large (let's say, ~0.5GB) xml structured like this:

<RootElem>
   <Elem TestAttrib="Some text some text some text"/>
   ...
   ...
   <Elem TestAttrib="Some text some text some text"/>
</RootElem>



I can see that XmlTextReader.ClearValueBuffer() is never called in this
case, so the attribute values of all processed elements are accumulated
in XmlTextReader.valueBuffer.

Would it be difficult to fix?

TIA,


/Sasha


More information about the Mono-devel-list mailing list