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

  • Home
  • SEARCH
  • 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 537149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:53:46+00:00 2026-05-13T09:53:46+00:00

I am developing a C# application which needs to process approximately 4,000,000 english sentences.

  • 0

I am developing a C# application which needs to process approximately 4,000,000 english sentences. All these sentences are being stored in a tree. Where each node in the tree is a class which has these fields:

class TreeNode
{
    protected string word;
    protected Dictionary<string, TreeNode> children;
}

My problem is that the application is using up all the RAM (I have 2 GB RAM) when it reaches the 2,000,000th sentence. So it only manages to process half the sentences and then it slows down drastically.

What can I do to try and reduce the memory footprint of the application?

EDIT: Let me explain a bit more my application. So I have approximately 300,000 english sentences, and from each sentence I am generating further sub sentences like this:

Example:
Sentence: Football is a very popular sport
Sub Sentences I need:

  1. Football is a very popular sport
  2. is a very popular sport
  3. a very popular sport
  4. very popular sport
  5. popular sport
  6. sport

Each sentence is stored in a tree word by word. So considering the example above, i have a TreeNode Class with the word field = “Football”, and the children list has the TreeNode for the word “is”. The child of the “is” node is the “a” node. The child for the “a” node is the “very” node. I need to store the sentences word by word since i need to be able to search for all the sentences starting with Example: “Football is”.

So basically for each word in a sentence i am creating a new (sub-sentence). And this is the reason I ultimately end up with 4,000,000 different sentences. Storing the data in a database is not an option, since the app needs to work on the whole structure at once. And it will further slow down the process if i had to stay writing all the data to a database.

Thanks

  • 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. Editorial Team
    Editorial Team
    2026-05-13T09:53:47+00:00Added an answer on May 13, 2026 at 9:53 am

    What is it you are using as the key? Where are you getting the data from? If these are words (not full setences), I’m wondering if you have a lot of duplicated keys (different string instances with the same fundamental value), in which case you might benefit from implementing a local interner to re-use the values (and let the transient copies get garbage collected).

    public sealed class StringCache {
        private readonly Dictionary<string,string> values
            = new Dictionary<string,string>(StringComparer.Ordinal);
        public string this[string value] {
            get {
                string cached;
                if (!values.TryGetValue(value, out cached)) {
                    values.Add(value, value);
                    cached = value;
                }
                return cached;
            }
        }
    }
    

    Instantiate this when building the tree, and use (when you think a value is likely to be duplicated):

    StringCache cache = new StringCache(); // re-use this instance while building
                                           // your tree
    ...
    string s = ... // whatever (from reading your input)
    s = cache[s];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Unfortunately setImageOpacity affects the whole image, so to leave the… May 16, 2026 at 3:15 pm
  • Editorial Team
    Editorial Team added an answer First, let's discuss IDE, ORM, and security, and DB: In… May 16, 2026 at 3:15 pm
  • Editorial Team
    Editorial Team added an answer Raveren's solution is efficient and beautiful, but here is another… May 16, 2026 at 3:15 pm

Trending Tags

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

Top Members

Related Questions

I am in the process of developing an application which uses a legacy USB
Issue:- I am developing a application which needs a new acceleration datum every 5
I'm developing a CakePHP 1.3 application which needs to login users backend and frontend.
I'm developing an application that needs to perform some processing on the user's Outlook
I'm developing a small utility application that needs to detect whether another one has
I am developing an application that needs to read back the whole frame from
I'm developing what is essentially a specialized firewall application. The solution needs to be
I'm developing an application targeting .NET Framework 2.0 using C# for which I need
I'm currently developing a C# application which will record registry changes, save them to
I'm developing a web application which processes invoices(the functionality is not limited to invoices,

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.