views:

129

answers:

2

Hi,

I have a small application that builds up a xml document using XDocument. However, after a while the app is using more than 1gb ram.

So I was wondering if there is anyway to make XDocument use the disk instead of in-memory. For example by opening a StreamWriter and save it to a file on the go.

Thank you in advance.

+1  A: 

Assuming you refer to the .net XDocument, you can instead use a XmlWriter (tutorial). The XmlWriter can be attached to any stream you like by using the XmlWriter.Create() method.

David Schmitt
+2  A: 

Are you sure that your document is so large as to consume 1 GB of memory?

Using a memory profiling tool such as ANTS Memory Profiler might help you discover what objects are remaining in memory.

Richard Ev
Actually, it's really that big and I didn't realize it. I suppose I'll have to go with the stream solution :) Thanks.
mortenbpost
I actually just checked and some of the xml files are over 300mb in size, so I guess the x xml classes has some overhead so the memory usage seems right.
mortenbpost
300Mb XML files - are you sure XML is the best format for this data?
Richard Ev