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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:55:46+00:00 2026-06-09T17:55:46+00:00

So from what I understand of a string vs StringBuilder is that string builder

  • 0

So from what I understand of a string vs StringBuilder is that string builder will actually modify the instance of itself while string will just make a new one. So if I understand this correctly then by using the string method for a constantly changing variable I could basically be eventually using all the memory until the computer needs to dump it to make room.

What I am doing is using an event handler to monitor serial communication. I will take in the data and parse it out plus display it in a text box. The event handler uses string to accomplish this currently. In concern for better programming and not using up all the memory when I don’t need to I am trying to clean up my code.

I started to code with string builder and begun to get the build error that StringBuilder does not contain a .contains method.

Basically I am curious if i should leave it alone? Should I approach this differently? and do I have the right understanding in that string will inevitably run me out of memory?

private void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e)
{
    SerialPort sp = (SerialPort)sender;

    string indata = sp.ReadExisting();
    rx.AppendText(Environment.NewLine + indata);
    string dataCheck = indata.ToUpper();
    if (dataCheck.Contains("CONNECT") || indata.Contains("CONNECTED"))
    {
        cState.Text = "Connected";
        connectLink();
    }
    if (dataCheck.Contains("NO CARRIER"))
    {
        cState.Text = "Disconnected";
        disconnect();
    }
    dataCheck = null;
}
  • 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-06-09T17:55:48+00:00Added an answer on June 9, 2026 at 5:55 pm

    You are incorrect; using String will not (in general) cause you to run out of memory.

    If you’re doing lots of concatenation, using string is less efficient, since it needs to build a new string and throw away the old string every time you concatenate.
    In such scenarios, you should use a StringBuilder to build the string, then call ToString() whenever you want to display it.

    Your code does not contain any concatenation, so using StringBuilder wouldn’t do any good.

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

Sidebar

Related Questions

Possible Duplicate: String vs StringBuilder I just revisited some of the books that I
I found that Maven implies specific directory layout. But I don't understand from here:
private Func GenerateWriter() { MethodInfo appendMethod = typeof(StringBuilder).GetMethod(Append, new[] { typeof(string) }); var buffer
I sort of understand the motivation for a String Builder class, but do all
Will a static final variable of a primitive or String type, that is assigned
From what I understand, when MySQL compares a string stored in utf8_general collation, it
So, for example, StringBuilder inherits from the abstract class AbstractStringBuilder . As I understand
From the design of Scala's collections I understand that something like: scala> BitSet(1,2,3) map
I understand from here that the name of an array is the address of
As you can understand from title, i modified Settings.cs file.Added some properties, some code

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.