I have written/deployed a C# Windows Service using VS.NET 2003. This service, over a period of several days, would grow in size to over 700 meg and start getting OutOfMemory exceptions. Also, the Page Faults would number in the millions.
The problem turned out to be in class level 2 XmlDocument objects. (Note: The class that used these 2 XmlDocument objects was a very busy class). The class would use these 2 XmlDocument objects to manipulate XML strings. The LoadXml() method was used to load the XML and then manipulate the XML as needed. There were 3 methods in this class that used these class level XmlDocument objects.
So, I deleted these class level XmlDocument objects and used local XmlDocument objects within each method that requres the use of a DOM.
The memory size issue and Page Faults have gone away...
Can anybody tell me why I can't use class level XmlDocument objects Keep in mind that the XmlDocument object does not have a Dispose() method.
TIA

I fixed by OutOfMemory Exceptions. Can somebody tell me why???
PaulVC
That makes roughly 40*2*(average_mem_use_of(xmldoc)). I took 40 as an average for your 30 - 50 class instances which all have 2 xml docs. How large are your xml docs I guess there will be some overhead to oraganize the nodes, so maybe some sort of hashmap, which has no good locally, hence a lot of page faults. How much memory does the machine have, how much is free
--
SvenC
Chazcon
SvenC,
Thanks for your interest here.
The XML stings that are used in these 2 XmlDocuments are from 50-300 bytes. The machine in question has a gig of memory.
It appears that when this class uses these 2 class level XmlDocument objects, each time the LoadXml() method is used, the memory for the previous XML string (that was loaded beforehand) is not being freed up by the Garbage Collection thread. Hence, the exe's memory size keeps getting bigger.
Do you agree with this
Duncan Woods
Yes, those small docs cannot create a 700MB memory usage alone. Might be that the old documents are not GC'ed
What methods/objects do you use to parse or navigate the xml documents
--
SvenC
GraemeP
There are about 30-50 instances of the class that use these 2 class level XmlDocument objects. Each class instance is a thread that communicates via TCP to a client process on a foreign machine. However, the foreign machines sends a "ping" XML message every 500 mills. Each incoming ping message requires the use of DOMs (i.e. the 2 class level XmlDocument objects). Typically, these class instances (i.e. threads) do not go out of scope (unless there is abnormal TCP communication problems).
Since these class instances do not go out of scope, these 2 class level XmlDocument objects (2 XmlDocument objects for each class instance) are indeed referenced for ever.
These classes use the LoadXml() method to parse/manipute/create incoming/outgoing XML messages.
But why the huge memory size and page faults
Is there a XmlDocument method that I should use prior to using the LoadXml() method
JunoJun
That busy class: how often is it created Do all references to such a busy class go out of scope after a while Otherwise I think that your busy class instances are referenced for ever and in turn reference XmlDocument for ever.
--
SvenC
Sundar.Iyer
Here are the XmlDocument methods/properties that I use and the number of source code lines that use the method/property:
LoadXml() in 4 locations
DocumentElement in 2 locations
ImportNode() in 3 locations
CreateNode() in 15 locations
DocumentElement.AppendChild() in 5 locations
OuterXml in 4 locations
As XML strings are manipulated, nodes are added as necessary