views:

240

answers:

2

This is probably along the lines of http://stackoverflow.com/questions/698147/net-collections-and-the-large-object-heap-loh

In .Net, I'm loading an XmlDocument with a string that makes ~200KB text document when the xml is converted to base64. The point being, the string should be allocated to the large object heap. I know from reading comparisons here that the XmlReader is the most efficient way to read the string, but the XmlDocument probably gives me the more straight forward read, with more functionality (xpath).

Each node of my XML should be a fairly small string, nothing near heading to the large object heap. Using Lutz .Net Reflector it appears the XmlDocument uses linked nodes internally.

So finally, my question: Will loading this string that saves ~200 KB (>85000 Bytes) cause yet another object to the LOH when using XmlDocument. We're a little worried about fragmenting the heap and leading to OOM errors. Or does the XmlDocument just happen to (at least for the case of data I'm asking about) create a lot of objects to the managed heap?

+1  A: 

Why are you loading the XML into a string to start with? Where is the data coming from? Can't you pass that (e.g. a Stream or TextReader) directly into XmlDocument to start with?

Jon Skeet
The string is coming from the database. We're building a vertical market app on top of the Microsoft Dynamics platform so using other type of database fields isn't an option for me.
benjynito
To be more clear, the string is coming from the Dynamics web service, which pulled it from the database.
benjynito
If it's coming from a web service, are you fetching it in an HTTP request? If you have control over that, you may be able to stream the result - if not, you're basically committed to having that 200K string in memory anyway.
Jon Skeet
I am fetching in an HTTP Request. Streaming the result is not something I'm familiar with, but I'll have to consider. I understand I may be committed to having that string in memory. I'm more concerned that I'm not adding on to that by using the XmlDocument class.Thanks for the response by the way.
benjynito
XmlDocument will certainly add to it, but I very much doubt that you'll end up with anything else in the LOH.
Jon Skeet
OK, what I meant by "add to it" was add to the LOH. Thank you.
benjynito
+2  A: 

It's only object of continous data that is larger than 85 kB that ends up in the large objects heap. For example large strings and arrays with ten thousands of elements.

An XmlDocument consists of a lot of small objects, so it will very rarely allocate anything on the large objects heap. The only chance for that is if a node contains tens of thousande of children, or if a value is longer than 42500 characters.

Guffa