java outOfMemoryError with stringbuilder

前端 未结 6 742
囚心锁ツ
囚心锁ツ 2020-12-15 12:44

I\'m getting a java outOfMemoryError when I call this method - i\'m using it in a loop to parse many large files in sequence. my guess is that result.toString()

6条回答
  •  無奈伤痛
    2020-12-15 13:23

    I reckon the problem with StringBuilder.append(). When Matcher appends sequence of characters to the Builder.

    As explained in article about OutOfMemoryError with StringBuilder/StringBuffer, it is a known issue that append() will double the capacity if internal buffer chars if the capacity is not sufficient. Go for streams as suggested by Erickson.

提交回复
热议问题