473,763 Members | 6,401 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Weird GC / Memory / XmlDocument.Loa dXML memory problem

ian
Hi, I've got the weirdest garbage collection problem - I'd appreciate any
advice you've got.

1. A class 'X' in a system I'm working on contains a reference to an
XmlDocument, populated via LoadXML.

2. Objects of type X are reused alot so different XML is loaded numerous
times.

3. If I keep this reference, the system looses more and more memory until it
hangs (> a gig of memory). If I replace this reference with a WeakReference
that holds the XMLDocument, my memory stays reasonably low and constant.

Can anyone understand this behaviour? I think it's safe to assume the
WeakReference is the only reference to the XML doc as otherwise the GC
wouldn't kill it. But then, if this is the only reference then why isn't the
memory being released when the XML is replaced normally?

Please don't suggest re-architecting the system - it's a mess, and there's
nothing I can do about it.

Cheers for any help.

Feb 18 '06 #1
2 2526
Hi Ian,
can you post a code example showing the problem, that would probably lead
to someone seeing the issue. The only way the CLR would run out of memory is
if the object still has a reference to it somewhere in the app so that it
can't be GCed, so something in your orignal code must be holding a reference
to this object. Did you add event handlers that listen to events in the
XMLDocument?

Mark.
--
http://www.markdawson.org
"ian" wrote:
Hi, I've got the weirdest garbage collection problem - I'd appreciate any
advice you've got.

1. A class 'X' in a system I'm working on contains a reference to an
XmlDocument, populated via LoadXML.

2. Objects of type X are reused alot so different XML is loaded numerous
times.

3. If I keep this reference, the system looses more and more memory until it
hangs (> a gig of memory). If I replace this reference with a WeakReference
that holds the XMLDocument, my memory stays reasonably low and constant.

Can anyone understand this behaviour? I think it's safe to assume the
WeakReference is the only reference to the XML doc as otherwise the GC
wouldn't kill it. But then, if this is the only reference then why isn't the
memory being released when the XML is replaced normally?

Please don't suggest re-architecting the system - it's a mess, and there's
nothing I can do about it.

Cheers for any help.

Feb 19 '06 #2
ian
Hi, there are a lot of event handlers - I don't know if any are connected to
the xmldoc, but whoever coded the system certainly got a bit excited about
them.

Do you know if event handlers are treated differently by the clr? It's
weird - if I have a weak reference, the object is destroyed (so there can be
no other references). However, if I have a normal reference, and null it,
the object hangs around - implying there are other references.

Thanks for the offer of looking at the code, but I don't think I can get
any.
"Mark R. Dawson" <Ma*********@di scussions.micro soft.com> wrote in message
news:47******** *************** ***********@mic rosoft.com...
Hi Ian,
can you post a code example showing the problem, that would probably lead
to someone seeing the issue. The only way the CLR would run out of memory
is
if the object still has a reference to it somewhere in the app so that it
can't be GCed, so something in your orignal code must be holding a
reference
to this object. Did you add event handlers that listen to events in the
XMLDocument?

Mark.
--
http://www.markdawson.org
"ian" wrote:
Hi, I've got the weirdest garbage collection problem - I'd appreciate any
advice you've got.

1. A class 'X' in a system I'm working on contains a reference to an
XmlDocument, populated via LoadXML.

2. Objects of type X are reused alot so different XML is loaded numerous
times.

3. If I keep this reference, the system looses more and more memory until
it
hangs (> a gig of memory). If I replace this reference with a
WeakReference
that holds the XMLDocument, my memory stays reasonably low and constant.

Can anyone understand this behaviour? I think it's safe to assume the
WeakReference is the only reference to the XML doc as otherwise the GC
wouldn't kill it. But then, if this is the only reference then why isn't
the
memory being released when the XML is replaced normally?

Please don't suggest re-architecting the system - it's a mess, and
there's
nothing I can do about it.

Cheers for any help.

Feb 19 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
301
by: Ruben Antonio Macias Doporto | last post by:
I have a ASP.NET app, and something weird is happening I have a xmldocument that has more than 10 nodes, I create an instance of a XMLNode and assign one node to it from the xmldocument. One line later I start a Loop with a for or a for each (If I use the For then the xmlnode instance is created inside the structure, if I use a for each then the xmlnode is instantiated at the beginning of the for each statement) well, then inside the loop...
6
7358
by: Yechezkal Gutfreund | last post by:
I have been using the following code (successfully) to read Xml formated text packets from a TCP stream. The output from the server stream consists of a sequence of well formed Xml documents written to the output stream. We are willing to pay $ to any expert (e.g. MVP) consultant who has to time to help us track down this problem. (we will discuss rates if you can prove your expertise, and problem solving approach).
1
17137
by: Martin Honnen | last post by:
With both .NET 1.0 and 1.1 I have found the following strange behaviour where System.Xml.XmlDocument.LoadXml doesn't throw an error when parsing a text node with a character reference to an invalid characters like &#x1;. Using the CreateTextNode method I create a text node containing "\u0001a" (C# string literal notation). As far as I understand the DOM allows that and an implementation is not required to throw an error. When OuterXml is...
4
4844
by: Robert Rossney | last post by:
I'm trying to send and receive XmlDocument objects using the System.Messaging.dll functions. The code I've written follows, as best I can tell, the methodology used in the sample code for the XmlMessageFormatter class. But it isn't working -- specifically, receiving isn't working. What am I doing wrong here? I begin by creating a MessageQueue object and setting up its XmlMessageFormatter to handle XmlDocument objects: System.Type...
2
8689
by: Eric Zechman via .NET 247 | last post by:
I have a project in which I get xml posted via a hidden form field (data=<xml></xml>). People are entering names like Bill & Sandy Smith. this is coming over as: <NameInfo><FamilyName><FamilyNames>David &amp; Karen</FamilyNames><Surname>Adams</Surname></FamilyName></NameInfo> When I try to load this up in a XmlDocument it blows up. string xmlData = Request.Form; dom.LoadXml(xmlData); results with this: "This is an unexpected token. The...
2
6209
by: Dave | last post by:
Hi, Is there an easier way to pull a subset of nodes from one XmlDocument to another? I have the code below but would like to know if there is a more streamlined method. Thanks, Dave XmlNodeList nodeList = doc1.SelectNodes("//row"); foreach (XmlNode nodeCode in nodeList) { sb.Append(nodeCode.OuterXml);
2
2760
by: Lupina | last post by:
Hi I want load whole xml file, I try do it in the same way as I did it in windows application. try { XmlDocument myDoc = new XmlDocument();
8
2508
by: GTi | last post by:
I need to load a XML into a string. Is it possible and how do I do it? I have a database using ODBC (MS SQL, P.SQL, Oracle.....) where the XML file is stored as a TEXT type. I can load this field as a string type. But I need to load this into a "XML reader", do any changes with the XML doc and store it again into the database. The database stuff is OK, I only need some help to load and save a XML as a string type. Can someone help me...
5
2172
by: Mike S | last post by:
I'm working on a .NET application that was under development by a previous developer, who is no longer working with the company. The program basically extracts records from a source database and outputs them in an XML document, mapping the source records into a third-party XML schema. The mapping process is handled by C# code that was auto-generated by Altova MapForce -- code was added to extract a subset of records from the source...
0
9563
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9386
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9997
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9822
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8821
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6642
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3917
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3522
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2793
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.