开发者社区> 问答> 正文

Java 中JDK 7 中的 subString如何 解决了内存泄露?

Java 中JDK 7 中的 subString如何 解决了内存泄露?

展开
收起
vncamyi27xznk 2021-11-12 19:09:50 547 0
1 条回答
写回答
取消 提交回答
  • "其使用创建了一个新字符串,避免对老字符串的引用。 Java 源码中关于这部分的主要代码如下: //JDK 7 public String(char value[], int offset, int count) { //check boundary this.value = Arrays.copyOfRange(value, offset, offset + count); } public String substring(int beginIndex, int endIndex) { //check boundary int subLen = endIndex - beginIndex; return new String(value, beginIndex, subLen); }

    这本电子书收录于开发者藏经阁,下载链接:https://developer.aliyun.com/topic/download?id=923"

    2021-11-12 21:33:13
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
Spring Cloud Alibaba - 重新定义 Java Cloud-Native 立即下载
The Reactive Cloud Native Arch 立即下载
JAVA开发手册1.5.0 立即下载