StringBuilder for string concatenation throws OutOfMemoryException

后端 未结 8 1653
南旧
南旧 2020-12-06 10:13

We mostly tend to following the above best practice.

Have a look at String vs StringBuilder

But StringBuilder could throw OutOfMemoryException even w

8条回答
  •  南方客
    南方客 (楼主)
    2020-12-06 10:39

    I encountered this exception with very large strings built sucessively with different stringbuilders (which should not have caused a problem as they were declared within anonymous functions), and finally solved it by reusing a single StringBuilder, declared outside of the anonymous function.

提交回复
热议问题