What is StringBuilder's RAM consumption like?

后端 未结 5 786
广开言路
广开言路 2021-01-12 15:39

We have a few operations where we are doing a large number of large string concatenations, and have recently encountered an out of memory exception. Unfortunately, debuggin

5条回答
  •  逝去的感伤
    2021-01-12 16:21

    I don't know about the exactly memory pattern of string builder but the common string is not an option.

    When you use the common string every concatenation creates another couple of string objects, and the memory consumption skyrocket, making the garbage collector being called too often.

    string a = "a";
    
    //creates object with a
    
    a += "b"
    
    /creates object with b, creates object with ab, assings object with ab to "a" pointer
    

提交回复
热议问题