TextBox.Text Leaking Memory in WPF Application

前端 未结 2 1392
再見小時候
再見小時候 2020-12-21 09:24

I have an application that does a large amount of number crunching on an array of numbers. I have it set to every 100,000 operations to display the status of those numbers.

2条回答
  •  抹茶落季
    2020-12-21 09:27

    +1 for Hans.

    Also, you're using StringBuilder. Awesome.

    However, you're concatenating FOUR strings for every item in arraystatus (which could be 100k for all I know) for each time your UI is updated, making StringBuilder pretty much pointless.

    Try

    s.Append(i.ToString());
    s.Append(":\t");
    s.Append(item.ToString());
    s.Append(i % 8 == 0 ? "\n" : "\t"));
    

    or, even better, try converting this to a single call of AppendFormat.

提交回复
热议问题