Topaz Filer: if you use e-mail for business, we can save you money and decrease your risk.
Massive memory use by XmlDocument
Messages   Related Types
This message was discovered on microsoft.public.dotnet.framework.performance.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.

James O (VIP)
GOOD ANSWER
I wrote a very simple test program that opens an XML document then releases
the reference to it:

static void Main(string[] args)
{
    XmlDocument doc = null;
    using (Stream s = File.OpenRead(args[0]))
    {
        doc = LoadXmlDocFromStream(s);
    }

    doc = null;
    
Console.ReadLine();
}

protected static XmlDocument LoadXmlDocFromStream(Stream s)
{
    XmlDocument d = new XmlDocument();
    d.PreserveWhitespace = false;
    XmlTextReader reader = new XmlTextReader(s);
    d.Load(reader);
    reader.Close();

    return d;
}

When I open a 20MB XML doc, I see through the CLR profiler that my CLR
memory usage jumps from 6K to a whopping 90MB. My working set size as shown
by the Task Manager jumps from 8MB to 210MB!

What's even more disturbing than these numbers is that when I release the
reference to the object, the CLR memory goes back down to 6K, but my working
set size remains at about 200MB! That just seems wrong.
Reply to this message...
Vote that this is a GOOD answer... (8 votes from other users already)
 
 
    
Andy Becker
GOOD ANSWER
"James O" <James Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Given that XML is about 90% redundant data, I'm not too surprised at the
bloat.

Don't worry too much about what shows up in task manager, that memory gets
returned to the OS when other applications request it.

Best Regards,

Andy

Reply to this message...
Vote that this is a GOOD answer... (9 votes from other users already)
 
 
    
David Browne
GOOD ANSWER
"James O" <James Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
> I wrote a very simple test program that opens an XML document then
releases
[Original message clipped]

.. . .

[Original message clipped]

You have discovered that XMLDocument is not an appropriate type for
manipulating very large XML documents. Try the streaming XMLReader instead.

David

Reply to this message...
Vote that this is a GOOD answer... (9 votes from other users already)
 
 
    
Dathon
GOOD ANSWER
Yeah, but there's bad and there's just plain broken. The huge memory
consumption is coming from somewhere other than the CLR heap, which is very
suspicious, IMO.

Any 'softies out there who know the inside scoop on this one?

Thx,
James

"David Browne" wrote:

[Original message clipped]

Reply to this message...
Vote that this is a GOOD answer... (9 votes from other users already)
 
 
 
System.Console
System.IO.File
System.Xml.XmlDocument
System.Xml.XmlTextReader




Ad
BootFX
Reliable and powerful .NET application framework.
Recession Busting Bespoke Software
Get through the recession by investing in bespoke software to decrease costs and create commercial opportunities.
Other DN247 Network Sites
.NET 247
SQL Server Wins
Old Skool Developer
 
Copyright © AMX Software Ltd 2008-2009. Portions copyright © Matthew Baxter-Reynolds 2001-2009. All rights reserved.
Contact Us - Terms of Use - Privacy Policy - .NET 247 is a member of the DN247 Network - 4.0.30129.1734