473,408 Members | 1,729 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,408 software developers and data experts.

xml resource cleanup?

I have the following code:

// code start
string resultValue;
XmlTextReader xtReader = new XmlTextReader(dataXml, XmlNodeType.Element,
null);
XPathDocument xpDoc = new XPathDocument(xtReader);
XPathNodeIterator iterator = xpDoc.CreateNavigator().Select("//result");
while(iterator.MoveNext())
{
resultValue = iterator.Current.Value;
break;
}
return resultValue;
// code end

Is there something that I can do to help clean up any resources right away
or do I just wait for the GC?
Nov 12 '05 #1
3 1893
Jiho Han wrote:
I have the following code:

// code start
string resultValue;
XmlTextReader xtReader = new XmlTextReader(dataXml, XmlNodeType.Element,
null);
XPathDocument xpDoc = new XPathDocument(xtReader);
XPathNodeIterator iterator = xpDoc.CreateNavigator().Select("//result");
while(iterator.MoveNext())
{
resultValue = iterator.Current.Value;
break;
}
return resultValue;
// code end

Is there something that I can do to help clean up any resources right away
or do I just wait for the GC?


It the code really ends here (so XPathDocument isn't referenced
anymore), do nothing, GC will take care.
Btw, using XmlTextReader directly you could save some memory avoiding
XPathDocument, which loads the whole XML document into memory.
--
Oleg Tkachenko [XML MVP, XmlInsider]
http://blog.tkachenko.com
Nov 12 '05 #2
Thanks Oleg.

I also like your input on the use of XmlTextReader. In this case, my xml
data is really small, so it really doesn't matter. However, if I were to
use XmlTextReader for something significantly larger, how would I select a
particular node?
I love xpath expressions and I'm hooked on it! I'm concerned that using
XmlTextReader means that I need to iterate through node after node until I
find the node I am looking for. Is there a way to use xpath with something
like XmlTextReader?

Thanks again!
Jiho

"Oleg Tkachenko [MVP]" <oleg@NO!SPAM!PLEASEtkachenko.com> wrote in message
news:ee**************@TK2MSFTNGP09.phx.gbl...
Jiho Han wrote:
I have the following code:

// code start
string resultValue;
XmlTextReader xtReader = new XmlTextReader(dataXml, XmlNodeType.Element,
null);
XPathDocument xpDoc = new XPathDocument(xtReader);
XPathNodeIterator iterator = xpDoc.CreateNavigator().Select("//result");
while(iterator.MoveNext())
{
resultValue = iterator.Current.Value;
break;
}
return resultValue;
// code end

Is there something that I can do to help clean up any resources right away or do I just wait for the GC?


It the code really ends here (so XPathDocument isn't referenced
anymore), do nothing, GC will take care.
Btw, using XmlTextReader directly you could save some memory avoiding
XPathDocument, which loads the whole XML document into memory.
--
Oleg Tkachenko [XML MVP, XmlInsider]
http://blog.tkachenko.com

Nov 12 '05 #3
This does not apply only to object in the System.XML namespace but in
general:

The "using" statement causes the C# compiler to generate a call to the
object's Dispose method immediately when it goes out of scope (at the ending
curly brace). Although one cannot explicitly control the Garbage Collector,
this will cause the memory of the object to be GC-ed as soon as possible.
Cheers,

Dimitre Novatchev [XML MVP],
FXSL developer, XML Insider,

http://fxsl.sourceforge.net/ -- the home of FXSL
Resume: http://fxsl.sf.net/DNovatchev/Resume/Res.html
"Jiho Han" <ji******@infinityinfo.com> wrote in message
news:ey**************@TK2MSFTNGP10.phx.gbl...
I have the following code:

// code start
string resultValue;
XmlTextReader xtReader = new XmlTextReader(dataXml, XmlNodeType.Element,
null);
XPathDocument xpDoc = new XPathDocument(xtReader);
XPathNodeIterator iterator = xpDoc.CreateNavigator().Select("//result");
while(iterator.MoveNext())
{
resultValue = iterator.Current.Value;
break;
}
return resultValue;
// code end

Is there something that I can do to help clean up any resources right away
or do I just wait for the GC?

Nov 12 '05 #4

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

Similar topics

4
by: Julie | last post by:
(I searched the FAQ, but didn't find anything relevant -- if there is, please post a link.) Is there a design paradigm that indicates that a class that manages an external resource should...
5
by: John Perks and Sarah Mount | last post by:
When handling resources in Python, where the scope of the resource is known, there seem to be two schools of thought: (1) Explicit: f = open(fname) try: # ... finally: f.close()
5
by: Dennis | last post by:
When I instantiate a Brush resource such as a solidbrush, do I need to dispose the resource when I'm finished or will it automatically be disposed when the function/sub it's used in ends? Thank...
0
by: Mythran | last post by:
I wrote some code that is supposed to enumerate through the specified file's win32 resources and return a string-array of all icon names. When it runs, it returns a string-array with a bunch of...
2
by: Robin Becker | last post by:
I'm thinking of using Tim Peters' excellent approach to resource clean up see http://mail.python.org/pipermail/python-dev/2006-April/063425.html but am wondering exactly what 'resources' are...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.