.NETGURU
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.
Post a new message to this list...

James O (VIP)
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...
 
    
Andy Becker
"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...
 
    
David Browne
"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...
 
    
Dathon
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...
 
 
System.Console
System.IO.File
System.Xml.XmlDocument
System.Xml.XmlTextReader




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification