这是在eclipsepowered上看到的。 Ed提到了eclipse-dev committers mailing list中, Jerome Lanneluc 指出的一个String#substring和String(String)的问题。按照Jerome的说法,使用String#substring()的时候,原有的长字符串所占据的空间仍然被占据,并没有释放,使用String(String)可以解决这个问题。Jerome的原文:
I just noticed that String#substring(…) shares the underlying char array. So if you have a big string, take a substring of it, throw away the big string, you will still hold on the big char array. A simple way to solve this is to make a copy of the substring using the String(String) constructor.
I saved 550KB in JDT Core by changing the following code:
String simpleName =
fullyQualifiedName.substring(fullQualifiedName.lastIndexOf('.'));
toString simpleName = new
String(fullyQualifiedName.substring(fullQualifiedName.lastIndexOf('.')));
Eclipse3.1发布以后,使用者发现,3.1占据了大量的Heap(大约200-300M)。 Eclipse的开发小组正在不断地解决这个问题,而String#substing的改进,将在Eclipse 3.1M6中发布(4月1日)。
这个提示,其实也可以运用在我们自己的项目之中
1480

被折叠的 条评论
为什么被折叠?



