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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:08:00+00:00 2026-05-22T03:08:00+00:00

I am getting a nice SystemOutOfMemory exception in my StringBuilders. It is not due

  • 0

I am getting a nice SystemOutOfMemory exception in my StringBuilders. It is not due to lack of ram, thus I believe it is memory fragmentation.

I have ~200 StringBuiler objects. All of these are reused regularly (with strBldr.clear()). This seems to cause my system to fragment the memory pretty bad. How can I solve this?

Thanks 🙂

EDIT:

Here are some data:

Max recorded size of input& stringBuilder: 4 146 698.

Avarage re-initiated stringBuilders/second: >120 (possibly >>120)

Length of input @ first error: 16 972 (string)

StringBuilder length @ first error: 16

Count of times a new stringBuilder had been made @ first error: ~32500

Total ram usage @ first error 637 448K

  • 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-22T03:08:01+00:00Added an answer on May 22, 2026 at 3:08 am

    I agree, most likely you are not running out of memory but into fragmentation.

    You have to get acquainted with fragmentation and the Large Object heap (LOH).

    You don’t provide any details so I can only give some very broad advice:

    • try to estimate how large your strings will be and use the Capacity parameter for a new SB
    • round up (really) those sizes to multiples of some number. This promotes re-use.
    • only use Clear() when you expect the new contents to be almost the same size as the old, growing it is what kills you.

    Edit

    Max recorded size of input& stringBuilder: 4 146 698.

    • Make sure there are no intermediates needed with a greater size, then
    • Create all StringBuilders like sb1 = new StringBuilder(4200000);
    • Don’t try to re-use them (too much / at all)
    • Don’t keep them around too long
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having nice first days using Yii but have some troubles with getting things
Python provides a nice method for getting length of an eager iterable, len(x) that
I'm having some trouble getting jQuery to play nice with DokuWiki - has anyone
Getting the subdomain from a URL sounds easy at first. http://www.domain.example Scan for the
Getting started with jquery and having trouble getting hello world type example going for
Without getting a degree in information retrieval, I'd like to know if there exists
Just getting my head around Ruby metaprogramming. The mixin/modules always manage to confuse me.
I getting the following error when I try to connect to my server app
Just getting started with Linq to SQL so forgive the newbie question. I'm trying
Im getting frustrated because of OpenDNS and other services (ie: roadrunner) that now always

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.