Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 43567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T15:30:56+00:00 2026-05-10T15:30:56+00:00

I need to parse a xml file which is practically an image of a

  • 0

I need to parse a xml file which is practically an image of a really big tree structure, so I’m using the XmlReader class to populate the tree ‘on the fly’. Each node is passed just the xml chunk it expects from its parent via the ReadSubtree() function. This has the advantage of not having to worry about when a node has consumed all its children. But now I’m wondering if this is actually a good idea, since there could be thousands of nodes and while reading the .NET source files I’ve found that a couple (and probably more) new objects are created with every ReadSubtree call, and no caching for reusable objects is made (that I’d seen).

Maybe ReadSubtree() was not thought to be massively used, or maybe I’m just worrying for nothing and I just need to call GC.Collect() after parsing the file…

Hope someone can shed some light on this.

Thanks in advance.

Update:

Thanks for the nice and insightful answers.

I had a deeper look at the .NET source code and I found it to be more complex than I first imagined. I’ve finally abandoned the idea of calling this function in this very scenario. As Stefan pointed out, the xml reader is never passed to outsiders and I can trust the code that parses the xml stream, (which is written by myself), so I’d rather force each node to be responsible for the amount of data they steal from the stream than using the not-so-thin-in-the-end ReadSubtree() function to just save a few lines of code.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T15:30:56+00:00Added an answer on May 10, 2026 at 3:30 pm

    ReadSubTree() gives you an XmlReader that wraps the original XmlReader. This new reader appears to consumers as a complete document. This might be important if the code you pass the subtree to thinks it is getting a standalone xml document. For example the Depth property of the new Reader starts out at 0. It is a pretty thin wrapper, so you won’t be using any more resources than you would if you used the original XmlReader directly, In the example you gave, it is rather likely that you aren’t really getting much out of the subtree reader.

    The big advantage in your case would be that the subtree reader can’t accidentally read past the subtree. Since the subtree reader isn’t very expensive, that safety might be enough, though it is generally more helpful when you need the subtree to look like a document or you don’t trust the code to only read its own subtree.

    As Will noted, you never want to call GC.Collect(). It will never improve performance.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 61k
  • Answers 61k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer So, will it be safe if I let people surf… May 11, 2026 at 9:42 am
  • added an answer I don't think that there is a single key command… May 11, 2026 at 9:42 am
  • added an answer It is possible to do it in smarty, but since… May 11, 2026 at 9:42 am

Related Questions

I need to parse a xml file which is practically an image of a
I need to parse Visual Studio automatically generated XML documentation to create a report.
For a one-shot operation, i need to parse the contents of an XML string
I need to parse a string like February 12, 1981 as a Date. I
I have a string like this that I need to parse into a 2D
I have a collection of HTML documents for which I need to parse the
I have an application running on multiple IIS servers that need to parse a
I have a query filter written in human readable language. I need to parse
I need to pause for maybe 500 miliseconds before I submit a form. Here
I'm working with Quickbook's IIF file format and I need to write a parser

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.