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
This question is similar to Getting Emacs fill-paragraph to play nice with javadoc-like comments
I'm having some trouble getting my Core Data entities to play nice and order
I am having trouble getting Restlet to play nice with GWT in the same
I've had lots of success in getting IE to play nice in the past,
I'm having problems with getting nhibernate to play nice with sqlite: My NHibernate configuration:
I'm just getting started learning SQLite . It would be nice to be able
I'm starting getting tired of this exception. Can't handle it, even so I'm using

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.