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 6545433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:35:05+00:00 2026-05-25T11:35:05+00:00

i have a large string (e.g. 20MB). i am now parsing this string. The

  • 0

i have a large string (e.g. 20MB).

i am now parsing this string. The problem is that strings in C# are immutable; this means that once i’ve created a substring, and looked at it, the memory is wasted.

Because of all the processing, memory is getting clogged up with String objects that i no longer used, need or reference; but it takes the garbage collector too long to free them.

So the application runs out of memory.

i could use the poorly performing club approach, and sprinkle a few thousand calls to:

GC.Collect();

everywhere, but that’s not really solving the issue.

i know StringBuilder exists when creating a large string.

i know TextReader exists to read a String into a char array.

i need to somehow “reuse” a string, making it no longer immutable, so that i don’t needlessly allocate gigabytes of memory when 1k will do.

  • 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-25T11:35:06+00:00Added an answer on May 25, 2026 at 11:35 am

    If your application is dying, that’s likely to be because you still have references to strings – not because the garbage collector is just failing to clean them up. I have seen it fail like that, but it’s pretty unlikely. Have you used a profiler to check that you really do have a lot of strings in memory at a time?

    The long and the short of it is that you can’t reuse a string to store different data – it just can’t be done. You can write your own equivalent if you like – but the chances of doing that efficiently and correctly are pretty slim. Now if you could give more information about what you’re doing, we may be able to suggest alternative approaches that don’t use so much memory.

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

Sidebar

Related Questions

I have a large string that contains fixed value fields, this group of fields
I have a large string, similar to this one: BREW pot HTCPCP/1.0 Accept-Additions: #milk;3#whiskey;splash
I have a arbitrarily large string of text from the user that needs to
I have this string containing a large chunk of html and am trying to
I have an app that needs to handle very large strings between a SQL
I have a large string variable that is assigned from a database column of
I have a large text string number (20 characters, no decimals) that needs to
I'm splitting a potentially large string (let's say 20MB, though this is entirely arbitrary)
I have a large string, and a part of this string starts like this:
I have a significantly large string that that I need to format so that

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.