473,406 Members | 2,369 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Weird GC / Memory / XmlDocument.LoadXML 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 2499
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*********@discussions.microsoft.com> wrote in message
news:47**********************************@microsof t.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
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...
6
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...
1
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...
4
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...
2
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:...
2
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 ...
2
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
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...
5
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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,...

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.