Memory Leak in StringBuilder when using Insert() and Clear()
问题 I need to add some lines to a StringBuilder, where the line added last should be at the beginning of the string and the oldest at the end. I add a new line like this: stringBuilder.Insert(0, "Some text." + Environment.NewLine); Once done, I empty the StringBuilder like this: stringBuilder.Clear(); I reuse the same StringBuilder many times, which leads to an Out of Memory exception over time. I investigated the problem with the test program below, which shows that when using Append() and Clear