且构网

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

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

更新时间:2022-06-22 02:42:15

存在内存泄漏的可能性,如果您采用相当大的字符串的子字符串而不进行复制(通常通过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 后发生了变化.请参阅 https://bugs.openjdk.java.net/browse/JDK-7197183一>.

Note that this has changed since Java 7u6. See https://bugs.openjdk.java.net/browse/JDK-7197183.

围绕实现 flyweight 模式的 String 对象的原始假设 不再被视为有效.

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

请参阅此答案了解更多信息信息.

See this answer for more info.