且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Java String.substring方法潜在的内存泄漏?

更新时间:2022-06-16 02:24:21

是如果您获取一个相当大的字符串的子字符串而不进行复制(通常通过 String(String)构造函数),则可能发生内存泄漏。

There is a potential for a memory leak, if you take a substring of a sizable string and not make a copy (usually via the String(String) constructor).

请注意,自 Java 7u6
请参阅 http://bugs.sun.com/view_bug.do?bug_id = 4513622

实现 String 对象周围的原始假设://en.wikipedia.org/wiki/Flyweight_patternrel =nofollow noreferrer> flyweight模式不再被视为有效。

The original assumptions around the String object implementing a flyweight pattern are no longer regarded as valid.

参见这个答案了解更多信息。